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_Sales
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: * Item option model
29: *
30: * @method Mage_Sales_Model_Resource_Quote_Item_Option _getResource()
31: * @method Mage_Sales_Model_Resource_Quote_Item_Option getResource()
32: * @method int getItemId()
33: * @method Mage_Sales_Model_Quote_Item_Option setItemId(int $value)
34: * @method int getProductId()
35: * @method Mage_Sales_Model_Quote_Item_Option setProductId(int $value)
36: * @method string getCode()
37: * @method Mage_Sales_Model_Quote_Item_Option setCode(string $value)
38: * @method string getValue()
39: * @method Mage_Sales_Model_Quote_Item_Option setValue(string $value)
40: *
41: * @category Mage
42: * @package Mage_Sales
43: * @author Magento Core Team <core@magentocommerce.com>
44: */
45: class Mage_Sales_Model_Quote_Item_Option extends Mage_Core_Model_Abstract
46: implements Mage_Catalog_Model_Product_Configuration_Item_Option_Interface
47: {
48: protected $_item;
49: protected $_product;
50:
51: /**
52: * Initialize resource model
53: */
54: protected function _construct()
55: {
56: $this->_init('sales/quote_item_option');
57: }
58:
59: /**
60: * Checks that item option model has data changes
61: *
62: * @return boolean
63: */
64: protected function _hasModelChanged()
65: {
66: if (!$this->hasDataChanges()) {
67: return false;
68: }
69:
70: return $this->_getResource()->hasDataChanged($this);
71: }
72:
73: /**
74: * Set quote item
75: *
76: * @param Mage_Sales_Model_Quote_Item $item
77: * @return Mage_Sales_Model_Quote_Item_Option
78: */
79: public function setItem($item)
80: {
81: $this->setItemId($item->getId());
82: $this->_item = $item;
83: return $this;
84: }
85:
86: /**
87: * Get option item
88: *
89: * @return Mage_Sales_Model_Quote_Item
90: */
91: public function getItem()
92: {
93: return $this->_item;
94: }
95:
96: /**
97: * Set option product
98: *
99: * @param Mage_Catalog_Model_Product $product
100: * @return Mage_Sales_Model_Quote_Item_Option
101: */
102: public function setProduct($product)
103: {
104: $this->setProductId($product->getId());
105: $this->_product = $product;
106: return $this;
107: }
108:
109: /**
110: * Get option product
111: *
112: * @return Mage_Catalog_Model_Product
113: */
114: public function getProduct()
115: {
116: return $this->_product;
117: }
118:
119: /**
120: * Get option value
121: *
122: * @return mixed
123: */
124: public function getValue()
125: {
126: return $this->_getData('value');
127: }
128:
129: /**
130: * Initialize item identifier before save data
131: *
132: * @return Mage_Sales_Model_Quote_Item_Option
133: */
134: protected function _beforeSave()
135: {
136: if ($this->getItem()) {
137: $this->setItemId($this->getItem()->getId());
138: }
139: return parent::_beforeSave();
140: }
141:
142: /**
143: * Clone option object
144: *
145: * @return Mage_Sales_Model_Quote_Item_Option
146: */
147: public function __clone()
148: {
149: $this->setId(null);
150: $this->_item = null;
151: return $this;
152: }
153: }
154: