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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Shipping\Block\Adminhtml;
/**
* Adminhtml shipment create
*
* @api
* @author Magento Core Team <core@magentocommerce.com>
* @since 100.0.2
*/
class View extends \Magento\Backend\Block\Widget\Form\Container
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
/**
* @return void
*/
protected function _construct()
{
$this->_objectId = 'shipment_id';
$this->_mode = 'view';
parent::_construct();
$this->buttonList->remove('reset');
$this->buttonList->remove('delete');
if (!$this->getShipment()) {
return;
}
if ($this->_authorization->isAllowed('Magento_Sales::emails')) {
$this->buttonList->update('save', 'label', __('Send Tracking Information'));
$this->buttonList->update(
'save',
'onclick',
"deleteConfirm('" . __(
'Are you sure you want to send a Shipment email to customer?'
) . "', '" . $this->getEmailUrl() . "')"
);
}
if ($this->getShipment()->getId()) {
$this->buttonList->add(
'print',
[
'label' => __('Print'),
'class' => 'save',
'onclick' => 'setLocation(\'' . $this->getPrintUrl() . '\')'
]
);
}
}
/**
* Retrieve shipment model instance
*
* @return \Magento\Sales\Model\Order\Shipment
*/
public function getShipment()
{
return $this->_coreRegistry->registry('current_shipment');
}
/**
* @return \Magento\Framework\Phrase
*/
public function getHeaderText()
{
if ($this->getShipment()->getEmailSent()) {
$emailSent = __('the shipment email was sent');
} else {
$emailSent = __('the shipment email is not sent');
}
return __(
'Shipment #%1 | %3 (%2)',
$this->getShipment()->getIncrementId(),
$emailSent,
$this->formatDate(
$this->_localeDate->date(new \DateTime($this->getShipment()->getCreatedAt())),
\IntlDateFormatter::MEDIUM,
true
)
);
}
/**
* @return string
*/
public function getBackUrl()
{
return $this->getUrl(
'sales/order/view',
[
'order_id' => $this->getShipment() ? $this->getShipment()->getOrderId() : null,
'active_tab' => 'order_shipments'
]
);
}
/**
* @return string
*/
public function getEmailUrl()
{
return $this->getUrl('adminhtml/order_shipment/email', ['shipment_id' => $this->getShipment()->getId()]);
}
/**
* @return string
*/
public function getPrintUrl()
{
return $this->getUrl('sales/shipment/print', ['shipment_id' => $this->getShipment()->getId()]);
}
/**
* @param bool $flag
* @return $this
*/
public function updateBackButtonUrl($flag)
{
if ($flag) {
if ($this->getShipment()->getBackUrl()) {
return $this->buttonList->update(
'back',
'onclick',
'setLocation(\'' . $this->getShipment()->getBackUrl() . '\')'
);
}
return $this->buttonList->update(
'back',
'onclick',
'setLocation(\'' . $this->getUrl('sales/shipment/') . '\')'
);
}
return $this;
}
}