/
View.php
327 lines (293 loc) · 11.4 KB
/
View.php
1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
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
325
326
327
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
<<<<<<< HEAD
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
=======
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
>>>>>>> origin/master
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Adminhtml sales order view
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Adminhtml_Block_Sales_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function __construct()
{
$this->_objectId = 'order_id';
$this->_controller = 'sales_order';
$this->_mode = 'view';
parent::__construct();
$this->_removeButton('delete');
$this->_removeButton('reset');
$this->_removeButton('save');
$this->setId('sales_order_view');
$order = $this->getOrder();
if ($this->_isAllowedAction('edit') && $order->canEdit()) {
$onclickJs = 'deleteConfirm(\''
. Mage::helper('sales')->__('Are you sure? This order will be canceled and a new one will be created instead')
. '\', \'' . $this->getEditUrl() . '\');';
$this->_addButton('order_edit', array(
'label' => Mage::helper('sales')->__('Edit'),
'onclick' => $onclickJs,
));
// see if order has non-editable products as items
$nonEditableTypes = array_keys($this->getOrder()->getResource()->aggregateProductsByTypes(
$order->getId(),
array_keys(Mage::getConfig()
->getNode('adminhtml/sales/order/create/available_product_types')
->asArray()
),
false
));
if ($nonEditableTypes) {
$this->_updateButton('order_edit', 'onclick',
'if (!confirm(\'' .
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
);
}
}
if ($this->_isAllowedAction('cancel') && $order->canCancel()) {
$message = Mage::helper('sales')->__('Are you sure you want to cancel this order?');
$this->_addButton('order_cancel', array(
'label' => Mage::helper('sales')->__('Cancel'),
'onclick' => 'deleteConfirm(\''.$message.'\', \'' . $this->getCancelUrl() . '\')',
));
}
if ($this->_isAllowedAction('emails') && !$order->isCanceled()) {
$message = Mage::helper('sales')->__('Are you sure you want to send order email to customer?');
$this->addButton('send_notification', array(
'label' => Mage::helper('sales')->__('Send Email'),
'onclick' => "confirmSetLocation('{$message}', '{$this->getEmailUrl()}')",
));
}
if ($this->_isAllowedAction('creditmemo') && $order->canCreditmemo()) {
$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?');
$onClick = "setLocation('{$this->getCreditmemoUrl()}')";
if ($order->getPayment()->getMethodInstance()->isGateway()) {
$onClick = "confirmSetLocation('{$message}', '{$this->getCreditmemoUrl()}')";
}
$this->_addButton('order_creditmemo', array(
'label' => Mage::helper('sales')->__('Credit Memo'),
'onclick' => $onClick,
'class' => 'go'
));
}
// invoice action intentionally
if ($this->_isAllowedAction('invoice') && $order->canVoidPayment()) {
$message = Mage::helper('sales')->__('Are you sure you want to void the payment?');
$this->addButton('void_payment', array(
'label' => Mage::helper('sales')->__('Void'),
'onclick' => "confirmSetLocation('{$message}', '{$this->getVoidPaymentUrl()}')",
));
}
if ($this->_isAllowedAction('hold') && $order->canHold()) {
$this->_addButton('order_hold', array(
'label' => Mage::helper('sales')->__('Hold'),
'onclick' => 'setLocation(\'' . $this->getHoldUrl() . '\')',
));
}
if ($this->_isAllowedAction('unhold') && $order->canUnhold()) {
$this->_addButton('order_unhold', array(
'label' => Mage::helper('sales')->__('Unhold'),
'onclick' => 'setLocation(\'' . $this->getUnholdUrl() . '\')',
));
}
if ($this->_isAllowedAction('review_payment')) {
if ($order->canReviewPayment()) {
$message = Mage::helper('sales')->__('Are you sure you want to accept this payment?');
$this->_addButton('accept_payment', array(
'label' => Mage::helper('sales')->__('Accept Payment'),
'onclick' => "confirmSetLocation('{$message}', '{$this->getReviewPaymentUrl('accept')}')",
));
$message = Mage::helper('sales')->__('Are you sure you want to deny this payment?');
$this->_addButton('deny_payment', array(
'label' => Mage::helper('sales')->__('Deny Payment'),
'onclick' => "confirmSetLocation('{$message}', '{$this->getReviewPaymentUrl('deny')}')",
));
}
if ($order->canFetchPaymentReviewUpdate()) {
$this->_addButton('get_review_payment_update', array(
'label' => Mage::helper('sales')->__('Get Payment Update'),
'onclick' => 'setLocation(\'' . $this->getReviewPaymentUrl('update') . '\')',
));
}
}
if ($this->_isAllowedAction('invoice') && $order->canInvoice()) {
$_label = $order->getForcedDoShipmentWithInvoice() ?
Mage::helper('sales')->__('Invoice and Ship') :
Mage::helper('sales')->__('Invoice');
$this->_addButton('order_invoice', array(
'label' => $_label,
'onclick' => 'setLocation(\'' . $this->getInvoiceUrl() . '\')',
'class' => 'go'
));
}
if ($this->_isAllowedAction('ship') && $order->canShip()
&& !$order->getForcedDoShipmentWithInvoice()) {
$this->_addButton('order_ship', array(
'label' => Mage::helper('sales')->__('Ship'),
'onclick' => 'setLocation(\'' . $this->getShipUrl() . '\')',
'class' => 'go'
));
}
if ($this->_isAllowedAction('reorder')
&& $this->helper('sales/reorder')->isAllowed($order->getStore())
&& $order->canReorderIgnoreSalable()
) {
$this->_addButton('order_reorder', array(
'label' => Mage::helper('sales')->__('Reorder'),
'onclick' => 'setLocation(\'' . $this->getReorderUrl() . '\')',
'class' => 'go'
));
}
}
/**
* Retrieve order model object
*
* @return Mage_Sales_Model_Order
*/
public function getOrder()
{
return Mage::registry('sales_order');
}
/**
* Retrieve Order Identifier
*
* @return int
*/
public function getOrderId()
{
return $this->getOrder()->getId();
}
public function getHeaderText()
{
if ($_extOrderId = $this->getOrder()->getExtOrderId()) {
$_extOrderId = '[' . $_extOrderId . '] ';
} else {
$_extOrderId = '';
}
return Mage::helper('sales')->__('Order # %s %s | %s', $this->getOrder()->getRealOrderId(), $_extOrderId, $this->formatDate($this->getOrder()->getCreatedAtDate(), 'medium', true));
}
public function getUrl($params='', $params2=array())
{
$params2['order_id'] = $this->getOrderId();
return parent::getUrl($params, $params2);
}
public function getEditUrl()
{
return $this->getUrl('*/sales_order_edit/start');
}
public function getEmailUrl()
{
return $this->getUrl('*/*/email');
}
public function getCancelUrl()
{
return $this->getUrl('*/*/cancel');
}
public function getInvoiceUrl()
{
return $this->getUrl('*/sales_order_invoice/start');
}
public function getCreditmemoUrl()
{
return $this->getUrl('*/sales_order_creditmemo/start');
}
public function getHoldUrl()
{
return $this->getUrl('*/*/hold');
}
public function getUnholdUrl()
{
return $this->getUrl('*/*/unhold');
}
public function getShipUrl()
{
return $this->getUrl('*/sales_order_shipment/start');
}
public function getCommentUrl()
{
return $this->getUrl('*/*/comment');
}
public function getReorderUrl()
{
return $this->getUrl('*/sales_order_create/reorder');
}
/**
* Payment void URL getter
*/
public function getVoidPaymentUrl()
{
return $this->getUrl('*/*/voidPayment');
}
protected function _isAllowedAction($action)
{
return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/' . $action);
}
/**
* Return back url for view grid
*
* @return string
*/
public function getBackUrl()
{
if ($this->getOrder()->getBackUrl()) {
return $this->getOrder()->getBackUrl();
}
return $this->getUrl('*/*/');
}
public function getReviewPaymentUrl($action)
{
return $this->getUrl('*/*/reviewPayment', array('action' => $action));
}
//
// /**
// * Return URL for accept payment action
// *
// * @return string
// */
// public function getAcceptPaymentUrl()
// {
// return $this->getUrl('*/*/reviewPayment', array('action' => 'accept'));
// }
//
// /**
// * Return URL for deny payment action
// *
// * @return string
// */
// public function getDenyPaymentUrl()
// {
// return $this->getUrl('*/*/reviewPayment', array('action' => 'deny'));
// }
//
// public function getPaymentReviewUpdateUrl()
// {
// return $this->getUrl('*/*/reviewPaymentUpdate');
// }
}