1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_SalesRule
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * SalesRule Coupon Model
30: *
31: * @method Mage_SalesRule_Model_Resource_Coupon _getResource()
32: * @method Mage_SalesRule_Model_Resource_Coupon getResource()
33: * @method int getRuleId()
34: * @method Mage_SalesRule_Model_Coupon setRuleId(int $value)
35: * @method string getCode()
36: * @method Mage_SalesRule_Model_Coupon setCode(string $value)
37: * @method int getUsageLimit()
38: * @method Mage_SalesRule_Model_Coupon setUsageLimit(int $value)
39: * @method int getUsagePerCustomer()
40: * @method Mage_SalesRule_Model_Coupon setUsagePerCustomer(int $value)
41: * @method int getTimesUsed()
42: * @method Mage_SalesRule_Model_Coupon setTimesUsed(int $value)
43: * @method string getExpirationDate()
44: * @method Mage_SalesRule_Model_Coupon setExpirationDate(string $value)
45: * @method int getIsPrimary()
46: * @method Mage_SalesRule_Model_Coupon setIsPrimary(int $value)
47: * @method int getType()
48: * @method Mage_SalesRule_Model_Coupon setType(int $value)
49: *
50: * @category Mage
51: * @package Mage_SalesRule
52: * @author Magento Core Team <core@magentocommerce.com>
53: */
54: class Mage_SalesRule_Model_Coupon extends Mage_Core_Model_Abstract
55: {
56: /**
57: * Coupon's owner rule instance
58: *
59: * @var Mage_SalesRule_Model_Rule
60: */
61: protected $_rule;
62:
63: protected function _construct()
64: {
65: parent::_construct();
66: $this->_init('salesrule/coupon');
67: }
68:
69: /**
70: * Processing object before save data
71: *
72: * @return Mage_Core_Model_Abstract
73: */
74: protected function _beforeSave()
75: {
76: if (!$this->getRuleId() && $this->_rule instanceof Mage_SalesRule_Model_Rule) {
77: $this->setRuleId($this->_rule->getId());
78: }
79: return parent::_beforeSave();
80: }
81:
82: /**
83: * Set rule instance
84: *
85: * @param Mage_SalesRule_Model_Rule
86: * @return Mage_SalesRule_Model_Coupon
87: */
88: public function setRule(Mage_SalesRule_Model_Rule $rule)
89: {
90: $this->_rule = $rule;
91: return $this;
92: }
93:
94: /**
95: * Load primary coupon for specified rule
96: *
97: * @param Mage_SalesRule_Model_Rule|int $rule
98: * @return Mage_SalesRule_Model_Coupon
99: */
100: public function loadPrimaryByRule($rule)
101: {
102: $this->getResource()->loadPrimaryByRule($this, $rule);
103: return $this;
104: }
105:
106: /**
107: * Load Shopping Cart Price Rule by coupon code
108: *
109: * @param string $couponCode
110: * @return Mage_SalesRule_Model_Coupon
111: */
112: public function loadByCode($couponCode)
113: {
114: $this->load($couponCode, 'code');
115: return $this;
116: }
117: }
118: