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: * Order status history comments
29: *
30: * @method Mage_Sales_Model_Resource_Order_Status_History _getResource()
31: * @method Mage_Sales_Model_Resource_Order_Status_History getResource()
32: * @method int getParentId()
33: * @method Mage_Sales_Model_Order_Status_History setParentId(int $value)
34: * @method int getIsCustomerNotified()
35: * @method int getIsVisibleOnFront()
36: * @method Mage_Sales_Model_Order_Status_History setIsVisibleOnFront(int $value)
37: * @method string getComment()
38: * @method Mage_Sales_Model_Order_Status_History setComment(string $value)
39: * @method string getStatus()
40: * @method Mage_Sales_Model_Order_Status_History setStatus(string $value)
41: * @method string getCreatedAt()
42: * @method Mage_Sales_Model_Order_Status_History setCreatedAt(string $value)
43: *
44: * @category Mage
45: * @package Mage_Sales
46: * @author Magento Core Team <core@magentocommerce.com>
47: */
48: class Mage_Sales_Model_Order_Status_History extends Mage_Sales_Model_Abstract
49: {
50: const CUSTOMER_NOTIFICATION_NOT_APPLICABLE = 2;
51:
52: /**
53: * Order instance
54: *
55: * @var Mage_Sales_Model_Order
56: */
57: protected $_order;
58:
59: /**
60: * Whether setting order again is required (for example when setting non-saved yet order)
61: * @deprecated after 1.4, wrong logic of setting order id
62: * @var bool
63: */
64: private $_shouldSetOrderBeforeSave = false;
65:
66: protected $_eventPrefix = 'sales_order_status_history';
67: protected $_eventObject = 'status_history';
68:
69: /**
70: * Initialize resource model
71: */
72: protected function _construct()
73: {
74: $this->_init('sales/order_status_history');
75: }
76:
77: /**
78: * Set order object and grab some metadata from it
79: *
80: * @param Mage_Sales_Model_Order $order
81: * @return Mage_Sales_Model_Order_Status_History
82: */
83: public function setOrder(Mage_Sales_Model_Order $order)
84: {
85: $this->_order = $order;
86: $this->setStoreId($order->getStoreId());
87: return $this;
88: }
89:
90: /**
91: * Notification flag
92: *
93: * @param mixed $flag OPTIONAL (notification is not applicable by default)
94: * @return Mage_Sales_Model_Order_Status_History
95: */
96: public function setIsCustomerNotified($flag = null)
97: {
98: if (is_null($flag)) {
99: $flag = self::CUSTOMER_NOTIFICATION_NOT_APPLICABLE;
100: }
101:
102: return $this->setData('is_customer_notified', $flag);
103: }
104:
105: /**
106: * Customer Notification Applicable check method
107: *
108: * @return boolean
109: */
110: public function isCustomerNotificationNotApplicable()
111: {
112: return $this->getIsCustomerNotified() == self::CUSTOMER_NOTIFICATION_NOT_APPLICABLE;
113: }
114:
115: /**
116: * Retrieve order instance
117: *
118: * @return Mage_Sales_Model_Order
119: */
120: public function getOrder()
121: {
122: return $this->_order;
123: }
124:
125: /**
126: * Retrieve status label
127: *
128: * @return string
129: */
130: public function getStatusLabel()
131: {
132: if($this->getOrder()) {
133: return $this->getOrder()->getConfig()->getStatusLabel($this->getStatus());
134: }
135: }
136:
137: /**
138: * Get store object
139: *
140: * @return unknown
141: */
142: public function getStore()
143: {
144: if ($this->getOrder()) {
145: return $this->getOrder()->getStore();
146: }
147: return Mage::app()->getStore();
148: }
149:
150: /**
151: * Set order again if required
152: *
153: * @return Mage_Sales_Model_Order_Status_History
154: */
155: protected function _beforeSave()
156: {
157: parent::_beforeSave();
158:
159: if (!$this->getParentId() && $this->getOrder()) {
160: $this->setParentId($this->getOrder()->getId());
161: }
162:
163: return $this;
164: }
165: }
166: