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: class Mage_Sales_Model_Order_Status extends Mage_Core_Model_Abstract
29: {
30:
31: protected function _construct()
32: {
33: $this->_init('sales/order_status');
34: }
35:
36: /**
37: * Assign order status to particular state
38: *
39: * @param string $state
40: * @param boolean $isDefault make the status as default one for state
41: * @return Mage_Sales_Model_Order_Status
42: */
43: public function assignState($state, $isDefault=false)
44: {
45: $this->_getResource()->beginTransaction();
46: try {
47: $this->_getResource()->assignState($this->getStatus(), $state, $isDefault);
48: $this->_getResource()->commit();
49: } catch (Exception $e) {
50: $this->_getResource()->rollBack();
51: throw $e;
52: }
53: return $this;
54: }
55:
56: /**
57: * Unassigns order status from particular state
58: *
59: * @param string $state
60: * @return Mage_Sales_Model_Order_Status
61: */
62: public function unassignState($state)
63: {
64: $this->_getResource()->beginTransaction();
65: try {
66: $this->_getResource()->unassignState($this->getStatus(), $state);
67: $this->_getResource()->commit();
68: } catch (Exception $e) {
69: $this->_getResource()->rollBack();
70: throw $e;
71: }
72: return $this;
73: }
74:
75: /**
76: * Getter for status labels per store
77: *
78: * @return array
79: */
80: public function getStoreLabels()
81: {
82: if ($this->hasData('store_labels')) {
83: return $this->_getData('store_labels');
84: }
85: $labels = $this->_getResource()->getStoreLabels($this);
86: $this->setData('store_labels', $labels);
87: return $labels;
88: }
89:
90: /**
91: * Get status label by store
92: *
93: * @param mixed $store
94: * @return string
95: */
96: public function getStoreLabel($store=null)
97: {
98: $store = Mage::app()->getStore($store);
99: $label = false;
100: if (!$store->isAdmin()) {
101: $labels = $this->getStoreLabels();
102: if (isset($labels[$store->getId()])) {
103: return $labels[$store->getId()];
104: }
105: }
106: return Mage::helper('sales')->__($this->getLabel());
107: }
108:
109: /**
110: * Load default status per state
111: *
112: * @param string $state
113: */
114: public function loadDefaultByState($state)
115: {
116: $this->load($state, 'default_state');
117: return $this;
118: }
119: }
120: