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_Block_Sales_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container
35: {
36:
37: public function __construct()
38: {
39: $this->_objectId = 'order_id';
40: $this->_controller = 'sales_order';
41: $this->_mode = 'view';
42:
43: parent::__construct();
44:
45: $this->_removeButton('delete');
46: $this->_removeButton('reset');
47: $this->_removeButton('save');
48: $this->setId('sales_order_view');
49: $order = $this->getOrder();
50:
51: if ($this->_isAllowedAction('edit') && $order->canEdit()) {
52: $onclickJs = 'deleteConfirm(\''
53: . Mage::helper('sales')->__('Are you sure? This order will be canceled and a new one will be created instead')
54: . '\', \'' . $this->getEditUrl() . '\');';
55: $this->_addButton('order_edit', array(
56: 'label' => Mage::helper('sales')->__('Edit'),
57: 'onclick' => $onclickJs,
58: ));
59:
60: $nonEditableTypes = array_keys($this->getOrder()->getResource()->aggregateProductsByTypes(
61: $order->getId(),
62: array_keys(Mage::getConfig()
63: ->getNode('adminhtml/sales/order/create/available_product_types')
64: ->asArray()
65: ),
66: false
67: ));
68: if ($nonEditableTypes) {
69: $this->_updateButton('order_edit', 'onclick',
70: 'if (!confirm(\'' .
71: Mage::helper('sales')->__('This order contains (%s) items and therefore cannot be edited through the admin interface at this time, if you wish to continue editing the (%s) items will be removed, the order will be canceled and a new order will be placed.', implode(', ', $nonEditableTypes), implode(', ', $nonEditableTypes)) . '\')) return false;' . $onclickJs
72: );
73: }
74: }
75:
76: if ($this->_isAllowedAction('cancel') && $order->canCancel()) {
77: $message = Mage::helper('sales')->__('Are you sure you want to cancel this order?');
78: $this->_addButton('order_cancel', array(
79: 'label' => Mage::helper('sales')->__('Cancel'),
80: 'onclick' => 'deleteConfirm(\''.$message.'\', \'' . $this->getCancelUrl() . '\')',
81: ));
82: }
83:
84: if ($this->_isAllowedAction('emails') && !$order->isCanceled()) {
85: $message = Mage::helper('sales')->__('Are you sure you want to send order email to customer?');
86: $this->addButton('send_notification', array(
87: 'label' => Mage::helper('sales')->__('Send Email'),
88: 'onclick' => "confirmSetLocation('{$message}', '{$this->getEmailUrl()}')",
89: ));
90: }
91:
92: if ($this->_isAllowedAction('creditmemo') && $order->canCreditmemo()) {
93: $message = Mage::helper('sales')->__('This will create an offline refund. To create an online refund, open an invoice and create credit memo for it. Do you wish to proceed?');
94: $onClick = "setLocation('{$this->getCreditmemoUrl()}')";
95: if ($order->getPayment()->getMethodInstance()->isGateway()) {
96: $onClick = "confirmSetLocation('{$message}', '{$this->getCreditmemoUrl()}')";
97: }
98: $this->_addButton('order_creditmemo', array(
99: 'label' => Mage::helper('sales')->__('Credit Memo'),
100: 'onclick' => $onClick,
101: 'class' => 'go'
102: ));
103: }
104:
105:
106: if ($this->_isAllowedAction('invoice') && $order->canVoidPayment()) {
107: $message = Mage::helper('sales')->__('Are you sure you want to void the payment?');
108: $this->addButton('void_payment', array(
109: 'label' => Mage::helper('sales')->__('Void'),
110: 'onclick' => "confirmSetLocation('{$message}', '{$this->getVoidPaymentUrl()}')",
111: ));
112: }
113:
114: if ($this->_isAllowedAction('hold') && $order->canHold()) {
115: $this->_addButton('order_hold', array(
116: 'label' => Mage::helper('sales')->__('Hold'),
117: 'onclick' => 'setLocation(\'' . $this->getHoldUrl() . '\')',
118: ));
119: }
120:
121: if ($this->_isAllowedAction('unhold') && $order->canUnhold()) {
122: $this->_addButton('order_unhold', array(
123: 'label' => Mage::helper('sales')->__('Unhold'),
124: 'onclick' => 'setLocation(\'' . $this->getUnholdUrl() . '\')',
125: ));
126: }
127:
128: if ($this->_isAllowedAction('review_payment')) {
129: if ($order->canReviewPayment()) {
130: $message = Mage::helper('sales')->__('Are you sure you want to accept this payment?');
131: $this->_addButton('accept_payment', array(
132: 'label' => Mage::helper('sales')->__('Accept Payment'),
133: 'onclick' => "confirmSetLocation('{$message}', '{$this->getReviewPaymentUrl('accept')}')",
134: ));
135: $message = Mage::helper('sales')->__('Are you sure you want to deny this payment?');
136: $this->_addButton('deny_payment', array(
137: 'label' => Mage::helper('sales')->__('Deny Payment'),
138: 'onclick' => "confirmSetLocation('{$message}', '{$this->getReviewPaymentUrl('deny')}')",
139: ));
140: }
141: if ($order->canFetchPaymentReviewUpdate()) {
142: $this->_addButton('get_review_payment_update', array(
143: 'label' => Mage::helper('sales')->__('Get Payment Update'),
144: 'onclick' => 'setLocation(\'' . $this->getReviewPaymentUrl('update') . '\')',
145: ));
146: }
147: }
148:
149: if ($this->_isAllowedAction('invoice') && $order->canInvoice()) {
150: $_label = $order->getForcedDoShipmentWithInvoice() ?
151: Mage::helper('sales')->__('Invoice and Ship') :
152: Mage::helper('sales')->__('Invoice');
153: $this->_addButton('order_invoice', array(
154: 'label' => $_label,
155: 'onclick' => 'setLocation(\'' . $this->getInvoiceUrl() . '\')',
156: 'class' => 'go'
157: ));
158: }
159:
160: if ($this->_isAllowedAction('ship') && $order->canShip()
161: && !$order->getForcedDoShipmentWithInvoice()) {
162: $this->_addButton('order_ship', array(
163: 'label' => Mage::helper('sales')->__('Ship'),
164: 'onclick' => 'setLocation(\'' . $this->getShipUrl() . '\')',
165: 'class' => 'go'
166: ));
167: }
168:
169: if ($this->_isAllowedAction('reorder')
170: && $this->helper('sales/reorder')->isAllowed($order->getStore())
171: && $order->canReorderIgnoreSalable()
172: ) {
173: $this->_addButton('order_reorder', array(
174: 'label' => Mage::helper('sales')->__('Reorder'),
175: 'onclick' => 'setLocation(\'' . $this->getReorderUrl() . '\')',
176: 'class' => 'go'
177: ));
178: }
179: }
180:
181: 182: 183: 184: 185:
186: public function getOrder()
187: {
188: return Mage::registry('sales_order');
189: }
190:
191: 192: 193: 194: 195:
196: public function getOrderId()
197: {
198: return $this->getOrder()->getId();
199: }
200:
201: public function ()
202: {
203: if ($_extOrderId = $this->getOrder()->getExtOrderId()) {
204: $_extOrderId = '[' . $_extOrderId . '] ';
205: } else {
206: $_extOrderId = '';
207: }
208: return Mage::helper('sales')->__('Order # %s %s | %s', $this->getOrder()->getRealOrderId(), $_extOrderId, $this->formatDate($this->getOrder()->getCreatedAtDate(), 'medium', true));
209: }
210:
211: public function getUrl($params='', $params2=array())
212: {
213: $params2['order_id'] = $this->getOrderId();
214: return parent::getUrl($params, $params2);
215: }
216:
217: public function getEditUrl()
218: {
219: return $this->getUrl('*/sales_order_edit/start');
220: }
221:
222: public function getEmailUrl()
223: {
224: return $this->getUrl('*/*/email');
225: }
226:
227: public function getCancelUrl()
228: {
229: return $this->getUrl('*/*/cancel');
230: }
231:
232: public function getInvoiceUrl()
233: {
234: return $this->getUrl('*/sales_order_invoice/start');
235: }
236:
237: public function getCreditmemoUrl()
238: {
239: return $this->getUrl('*/sales_order_creditmemo/start');
240: }
241:
242: public function getHoldUrl()
243: {
244: return $this->getUrl('*/*/hold');
245: }
246:
247: public function getUnholdUrl()
248: {
249: return $this->getUrl('*/*/unhold');
250: }
251:
252: public function getShipUrl()
253: {
254: return $this->getUrl('*/sales_order_shipment/start');
255: }
256:
257: public function ()
258: {
259: return $this->getUrl('*/*/comment');
260: }
261:
262: public function getReorderUrl()
263: {
264: return $this->getUrl('*/sales_order_create/reorder');
265: }
266:
267: 268: 269:
270: public function getVoidPaymentUrl()
271: {
272: return $this->getUrl('*/*/voidPayment');
273: }
274:
275: protected function _isAllowedAction($action)
276: {
277: return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/' . $action);
278: }
279:
280: 281: 282: 283: 284:
285: public function getBackUrl()
286: {
287: if ($this->getOrder()->getBackUrl()) {
288: return $this->getOrder()->getBackUrl();
289: }
290:
291: return $this->getUrl('*/*/');
292: }
293:
294: public function getReviewPaymentUrl($action)
295: {
296: return $this->getUrl('*/*/reviewPayment', array('action' => $action));
297: }
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323: }
324: