Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
View.php
Go to the documentation of this file.
1 <?php
9 
16 class View extends \Magento\Backend\Block\Widget\Form\Container
17 {
23  protected $_blockGroup = 'Magento_Sales';
24 
30  protected $_coreRegistry = null;
31 
37  protected $_salesConfig;
38 
44  protected $_reorderHelper;
45 
53  public function __construct(
54  \Magento\Backend\Block\Widget\Context $context,
55  \Magento\Framework\Registry $registry,
56  \Magento\Sales\Model\Config $salesConfig,
57  \Magento\Sales\Helper\Reorder $reorderHelper,
58  array $data = []
59  ) {
60  $this->_reorderHelper = $reorderHelper;
61  $this->_coreRegistry = $registry;
62  $this->_salesConfig = $salesConfig;
63  parent::__construct($context, $data);
64  }
65 
74  protected function _construct()
75  {
76  $this->_objectId = 'order_id';
77  $this->_controller = 'adminhtml_order';
78  $this->_mode = 'view';
79 
80  parent::_construct();
81 
82  $this->removeButton('delete');
83  $this->removeButton('reset');
84  $this->removeButton('save');
85  $this->setId('sales_order_view');
86  $order = $this->getOrder();
87 
88  if (!$order) {
89  return;
90  }
91 
92  if ($this->_isAllowedAction('Magento_Sales::actions_edit') && $order->canEdit()) {
93  $onclickJs = 'jQuery(\'#order_edit\').orderEditDialog({message: \''
94  . $this->getEditMessage($order) . '\', url: \'' . $this->getEditUrl()
95  . '\'}).orderEditDialog(\'showDialog\');';
96 
97  $this->addButton(
98  'order_edit',
99  [
100  'label' => __('Edit'),
101  'class' => 'edit primary',
102  'onclick' => $onclickJs,
103  'data_attribute' => [
104  'mage-init' => '{"orderEditDialog":{}}',
105  ]
106  ]
107  );
108  }
109 
110  if ($this->_isAllowedAction('Magento_Sales::cancel') && $order->canCancel()) {
111  $this->addButton(
112  'order_cancel',
113  [
114  'label' => __('Cancel'),
115  'class' => 'cancel',
116  'id' => 'order-view-cancel-button',
117  'data_attribute' => [
118  'url' => $this->getCancelUrl()
119  ]
120  ]
121  );
122  }
123 
124  if ($this->_isAllowedAction('Magento_Sales::emails') && !$order->isCanceled()) {
125  $message = __('Are you sure you want to send an order email to customer?');
126  $this->addButton(
127  'send_notification',
128  [
129  'label' => __('Send Email'),
130  'class' => 'send-email',
131  'onclick' => "confirmSetLocation('{$message}', '{$this->getEmailUrl()}')"
132  ]
133  );
134  }
135 
136  if ($this->_isAllowedAction('Magento_Sales::creditmemo') && $order->canCreditmemo()) {
137  $message = __(
138  'This will create an offline refund. ' .
139  'To create an online refund, open an invoice and create credit memo for it. Do you want to continue?'
140  );
141  $onClick = "setLocation('{$this->getCreditmemoUrl()}')";
142  if ($order->getPayment()->getMethodInstance()->isGateway()) {
143  $onClick = "confirmSetLocation('{$message}', '{$this->getCreditmemoUrl()}')";
144  }
145  $this->addButton(
146  'order_creditmemo',
147  ['label' => __('Credit Memo'), 'onclick' => $onClick, 'class' => 'credit-memo']
148  );
149  }
150 
151  // invoice action intentionally
152  if ($this->_isAllowedAction('Magento_Sales::invoice') && $order->canVoidPayment()) {
153  $message = __('Are you sure you want to void the payment?');
154  $this->addButton(
155  'void_payment',
156  [
157  'label' => __('Void'),
158  'onclick' => "confirmSetLocation('{$message}', '{$this->getVoidPaymentUrl()}')"
159  ]
160  );
161  }
162 
163  if ($this->_isAllowedAction('Magento_Sales::hold') && $order->canHold()) {
164  $this->addButton(
165  'order_hold',
166  [
167  'label' => __('Hold'),
168  'class' => __('hold'),
169  'id' => 'order-view-hold-button',
170  'data_attribute' => [
171  'url' => $this->getHoldUrl()
172  ]
173  ]
174  );
175  }
176 
177  if ($this->_isAllowedAction('Magento_Sales::unhold') && $order->canUnhold()) {
178  $this->addButton(
179  'order_unhold',
180  [
181  'label' => __('Unhold'),
182  'class' => __('unhold'),
183  'id' => 'order-view-unhold-button',
184  'data_attribute' => [
185  'url' => $this->getUnholdUrl()
186  ]
187  ]
188  );
189  }
190 
191  if ($this->_isAllowedAction('Magento_Sales::review_payment')) {
192  if ($order->canReviewPayment()) {
193  $message = __('Are you sure you want to accept this payment?');
194  $this->addButton(
195  'accept_payment',
196  [
197  'label' => __('Accept Payment'),
198  'onclick' => "confirmSetLocation('{$message}', '{$this->getReviewPaymentUrl('accept')}')"
199  ]
200  );
201  $message = __('Are you sure you want to deny this payment?');
202  $this->addButton(
203  'deny_payment',
204  [
205  'label' => __('Deny Payment'),
206  'onclick' => "confirmSetLocation('{$message}', '{$this->getReviewPaymentUrl('deny')}')"
207  ]
208  );
209  }
210  if ($order->canFetchPaymentReviewUpdate()) {
211  $this->addButton(
212  'get_review_payment_update',
213  [
214  'label' => __('Get Payment Update'),
215  'onclick' => 'setLocation(\'' . $this->getReviewPaymentUrl('update') . '\')'
216  ]
217  );
218  }
219  }
220 
221  if ($this->_isAllowedAction('Magento_Sales::invoice') && $order->canInvoice()) {
222  $_label = $order->getForcedShipmentWithInvoice() ? __('Invoice and Ship') : __('Invoice');
223  $this->addButton(
224  'order_invoice',
225  [
226  'label' => $_label,
227  'onclick' => 'setLocation(\'' . $this->getInvoiceUrl() . '\')',
228  'class' => 'invoice'
229  ]
230  );
231  }
232 
233  if ($this->_isAllowedAction(
234  'Magento_Sales::ship'
235  ) && $order->canShip() && !$order->getForcedShipmentWithInvoice()
236  ) {
237  $this->addButton(
238  'order_ship',
239  [
240  'label' => __('Ship'),
241  'onclick' => 'setLocation(\'' . $this->getShipUrl() . '\')',
242  'class' => 'ship'
243  ]
244  );
245  }
246 
247  if ($this->_isAllowedAction(
248  'Magento_Sales::reorder'
249  ) && $this->_reorderHelper->isAllowed(
250  $order->getStore()
251  ) && $order->canReorderIgnoreSalable()
252  ) {
253  $this->addButton(
254  'order_reorder',
255  [
256  'label' => __('Reorder'),
257  'onclick' => 'setLocation(\'' . $this->getReorderUrl() . '\')',
258  'class' => 'reorder'
259  ]
260  );
261  }
262  }
263 
269  public function getOrder()
270  {
271  return $this->_coreRegistry->registry('sales_order');
272  }
273 
279  public function getOrderId()
280  {
281  return $this->getOrder() ? $this->getOrder()->getId() : null;
282  }
283 
289  public function getHeaderText()
290  {
291  $_extOrderId = $this->getOrder()->getExtOrderId();
292  if ($_extOrderId) {
293  $_extOrderId = '[' . $_extOrderId . '] ';
294  } else {
295  $_extOrderId = '';
296  }
297  return __(
298  'Order # %1 %2 | %3',
299  $this->getOrder()->getRealOrderId(),
300  $_extOrderId,
301  $this->formatDate(
302  $this->_localeDate->date(new \DateTime($this->getOrder()->getCreatedAt())),
303  \IntlDateFormatter::MEDIUM,
304  true
305  )
306  );
307  }
308 
316  public function getUrl($params = '', $params2 = [])
317  {
318  $params2['order_id'] = $this->getOrderId();
319  return parent::getUrl($params, $params2);
320  }
321 
327  public function getEditUrl()
328  {
329  return $this->getUrl('sales/order_edit/start');
330  }
331 
337  public function getEmailUrl()
338  {
339  return $this->getUrl('sales/*/email');
340  }
341 
347  public function getCancelUrl()
348  {
349  return $this->getUrl('sales/*/cancel');
350  }
351 
357  public function getInvoiceUrl()
358  {
359  return $this->getUrl('sales/order_invoice/start');
360  }
361 
367  public function getCreditmemoUrl()
368  {
369  return $this->getUrl('sales/order_creditmemo/start');
370  }
371 
377  public function getHoldUrl()
378  {
379  return $this->getUrl('sales/*/hold');
380  }
381 
387  public function getUnholdUrl()
388  {
389  return $this->getUrl('sales/*/unhold');
390  }
391 
397  public function getShipUrl()
398  {
399  return $this->getUrl('adminhtml/order_shipment/start');
400  }
401 
407  public function getCommentUrl()
408  {
409  return $this->getUrl('sales/*/comment');
410  }
411 
417  public function getReorderUrl()
418  {
419  return $this->getUrl('sales/order_create/reorder');
420  }
421 
427  public function getVoidPaymentUrl()
428  {
429  return $this->getUrl('sales/*/voidPayment');
430  }
431 
438  protected function _isAllowedAction($resourceId)
439  {
440  return $this->_authorization->isAllowed($resourceId);
441  }
442 
448  public function getBackUrl()
449  {
450  if ($this->getOrder() && $this->getOrder()->getBackUrl()) {
451  return $this->getOrder()->getBackUrl();
452  }
453 
454  return $this->getUrl('sales/*/');
455  }
456 
463  public function getReviewPaymentUrl($action)
464  {
465  return $this->getUrl('sales/*/reviewPayment', ['action' => $action]);
466  }
467 
472  protected function getEditMessage($order)
473  {
474  // see if order has non-editable products as items
475  $nonEditableTypes = $this->getNonEditableTypes($order);
476  if (!empty($nonEditableTypes)) {
477  return __(
478  'This order contains (%1) items and therefore cannot be edited through the admin interface. ' .
479  'If you wish to continue editing, the (%2) items will be removed, ' .
480  ' the order will be canceled and a new order will be placed.',
481  implode(', ', $nonEditableTypes),
482  implode(', ', $nonEditableTypes)
483  );
484  }
485  return __('Are you sure? This order will be canceled and a new one will be created instead.');
486  }
487 
493  {
494  return array_keys(
495  $this->getOrder()->getResource()->aggregateProductsByTypes(
496  $order->getId(),
497  $this->_salesConfig->getAvailableProductTypes(),
498  false
499  )
500  );
501  }
502 }
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Framework\Registry $registry, \Magento\Sales\Model\Config $salesConfig, \Magento\Sales\Helper\Reorder $reorderHelper, array $data=[])
Definition: View.php:53
return false
Definition: gallery.phtml:36
$order
Definition: order.php:55
__()
Definition: __.php:13
$message
return['app/code */registration.php', 'app/design */registration.php', 'lib/internal **/registration.php']
else function()
foreach( $block->getMultipleRows( $_item) as $_i)($_isFirstRow) continue
addButton($buttonId, $data, $level=0, $sortOrder=0, $region='toolbar')
Definition: Container.php:85