1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Sales_Order_StatusController extends Mage_Adminhtml_Controller_Action
35: {
36: 37: 38: 39:
40: protected function _construct()
41: {
42: $this->setUsedModuleName('Mage_Sales');
43: }
44:
45: 46: 47: 48: 49:
50: protected function _initStatus()
51: {
52: $statusCode = $this->getRequest()->getParam('status');
53: if ($statusCode) {
54: $status = Mage::getModel('sales/order_status')->load($statusCode);
55: } else {
56: $status = false;
57: }
58: return $status;
59: }
60:
61: 62: 63:
64: public function indexAction()
65: {
66: $this->_title($this->__('Sales'))->_title($this->__('Order Statuses'));
67: $this->loadLayout()->_setActiveMenu('system')->renderLayout();
68: }
69:
70: 71: 72:
73: public function newAction()
74: {
75: $data = $this->_getSession()->getFormData(true);
76: if ($data) {
77: $status = Mage::getModel('sales/order_status')
78: ->setData($data);
79: Mage::register('current_status', $status);
80: }
81: $this->_title($this->__('Sales'))->_title($this->__('Create New Order Status'));
82: $this->loadLayout()
83: ->renderLayout();
84: }
85:
86: 87: 88:
89: public function editAction()
90: {
91: $status = $this->_initStatus();
92: if ($status) {
93: Mage::register('current_status', $status);
94: $this->_title($this->__('Sales'))->_title($this->__('Edit Order Status'));
95: $this->loadLayout()
96: ->renderLayout();
97: } else {
98: $this->_getSession()->addError(
99: Mage::helper('sales')->__('Order status does not exist.')
100: );
101: $this->_redirect('*/');
102: }
103: }
104:
105: 106: 107:
108: public function saveAction()
109: {
110: $data = $this->getRequest()->getPost();
111: $isNew = $this->getRequest()->getParam('is_new');
112: if ($data) {
113:
114: $statusCode = $this->getRequest()->getParam('status');
115:
116:
117:
118: $helper = Mage::helper('adminhtml');
119: if ($isNew) {
120: $statusCode = $data['status'] = $helper->stripTags($data['status']);
121: }
122: $data['label'] = $helper->stripTags($data['label']);
123: foreach ($data['store_labels'] as &$label) {
124: $label = $helper->stripTags($label);
125: }
126:
127: $status = Mage::getModel('sales/order_status')
128: ->load($statusCode);
129:
130: if ($isNew && $status->getStatus()) {
131: $this->_getSession()->addError(
132: Mage::helper('sales')->__('Order status with the same status code already exist.')
133: );
134: $this->_getSession()->setFormData($data);
135: $this->_redirect('*/*/new');
136: return;
137: }
138:
139: $status->setData($data)
140: ->setStatus($statusCode);
141: try {
142: $status->save();
143: $this->_getSession()->addSuccess(Mage::helper('sales')->__('The order status has been saved.'));
144: $this->_redirect('*/*/');
145: return;
146: } catch (Mage_Core_Exception $e) {
147: $this->_getSession()->addError($e->getMessage());
148: } catch (Exception $e) {
149: $this->_getSession()->addException(
150: $e,
151: Mage::helper('sales')->__('An error occurred while saving order status. The status has not been added.')
152: );
153: }
154: $this->_getSession()->setFormData($data);
155: if ($isNew) {
156: $this->_redirect('*/*/new');
157: } else {
158: $this->_redirect('*/*/edit', array('status' => $this->getRequest()->getParam('status')));
159: }
160: return;
161: }
162: $this->_redirect('*/*/');
163: }
164:
165: 166: 167:
168: public function assignAction()
169: {
170: $this->_title($this->__('Sales'))->_title($this->__('Assign Order Status to State'));
171: $this->loadLayout()
172: ->renderLayout();
173: }
174:
175: 176: 177:
178: public function assignPostAction()
179: {
180: $data = $this->getRequest()->getPost();
181: if ($data) {
182: $state = $this->getRequest()->getParam('state');
183: $isDefault = $this->getRequest()->getParam('is_default');
184: $status = $this->_initStatus();
185: if ($status && $status->getStatus()) {
186: try {
187: $status->assignState($state, $isDefault);
188: $this->_getSession()->addSuccess(Mage::helper('sales')->__('The order status has been assigned.'));
189: $this->_redirect('*/*/');
190: return;
191: } catch (Mage_Core_Exception $e) {
192: $this->_getSession()->addError($e->getMessage());
193: } catch (Exception $e) {
194: $this->_getSession()->addException(
195: $e,
196: Mage::helper('sales')->__('An error occurred while assigning order status. Status has not been assigned.')
197: );
198: }
199: } else {
200: $this->_getSession()->addError(Mage::helper('sales')->__('Order status does not exist.'));
201: }
202: $this->_redirect('*/*/assign');
203: return;
204: }
205: $this->_redirect('*/*/');
206: }
207:
208: public function unassignAction()
209: {
210: $state = $this->getRequest()->getParam('state');
211: $status = $this->_initStatus();
212: if ($status) {
213: try {
214: $status->unassignState($state);
215: $this->_getSession()->addSuccess(Mage::helper('sales')->__('The order status has been unassigned.'));
216: } catch (Mage_Core_Exception $e) {
217: $this->_getSession()->addError($e->getMessage());
218: } catch (Exception $e) {
219: $this->_getSession()->addException(
220: $e,
221: Mage::helper('sales')->__('An error occurred while unassigning order status.')
222: );
223: }
224: } else {
225: $this->_getSession()->addError(Mage::helper('sales')->__('Order status does not exist.'));
226: }
227: $this->_redirect('*/*/');
228: }
229:
230: 231: 232: 233: 234:
235: protected function _isAllowed()
236: {
237: return Mage::getSingleton('admin/session')->isAllowed('system/order_statuses');
238: }
239: }
240: