|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
* @category Mygento |
|
7
|
|
|
* @package Mygento_Yandexdelivery |
|
8
|
|
|
* @copyright 2017 NKS LLC. (http://www.mygento.ru) |
|
9
|
|
|
* @license GPLv2 |
|
10
|
|
|
*/ |
|
11
|
|
|
class Mygento_Yandexdelivery_Block_Adminhtml_Order_View_Tab extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
public function _construct() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::_construct(); |
|
17
|
|
|
$this->setTemplate('mygento/yandexdelivery/order/view/tab.phtml'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function getTabLabel() |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->__('Yandexdelivery shipping'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function getTabTitle() |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->getTabLabel(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function canShowTab() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->isShippedBy(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function isHidden() |
|
36
|
|
|
{ |
|
37
|
|
|
return false; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getOrder() |
|
41
|
|
|
{ |
|
42
|
|
|
return Mage::registry('current_order'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
protected function isShippedBy() |
|
46
|
|
|
{ |
|
47
|
|
|
return Mage::helper('yandexdelivery')->isShippedBy($this->getOrder()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function hasTrack($order) |
|
51
|
|
|
{ |
|
52
|
|
|
foreach ($order->getShipmentsCollection() as $_shipment) { |
|
53
|
|
|
foreach ($_shipment->getAllTracks() as $tracknum) { |
|
54
|
|
|
return $tracknum->getNumber(); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function hasYdId() |
|
61
|
|
|
{ |
|
62
|
|
|
if (Mage::getModel('yandexdelivery/carrier')->getYdId($this->getOrder()->getId())) { |
|
63
|
|
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getAjaxButton($name, $title, $url) |
|
69
|
|
|
{ |
|
70
|
|
|
$html = $this->getLayout()->createBlock('adminhtml/widget_button') |
|
71
|
|
|
->setData([ |
|
72
|
|
|
'label' => Mage::helper('yandexdelivery')->__($title), |
|
73
|
|
|
'onclick' => '' . $name . '.click(\'' . $url . '\');', |
|
74
|
|
|
'class' => 'task' |
|
75
|
|
|
])->toHtml(); |
|
76
|
|
|
$html .= '<script type = "text/javascript"> |
|
77
|
|
|
//<![CDATA[ |
|
78
|
|
|
var ' . $name . '; |
|
79
|
|
|
' . $name . ' = { |
|
80
|
|
|
click: function (url) { |
|
81
|
|
|
var request = new Ajax.Request( |
|
82
|
|
|
url, |
|
83
|
|
|
{ |
|
84
|
|
|
method: "get", |
|
85
|
|
|
onComplete: this.onComplete, |
|
86
|
|
|
onSuccess: this.onSave |
|
87
|
|
|
} |
|
88
|
|
|
); |
|
89
|
|
|
}, |
|
90
|
|
|
onComplete: function (transport) { |
|
91
|
|
|
if (transport && transport.responseText) { |
|
92
|
|
|
try { |
|
93
|
|
|
response = eval("(" + transport.responseText + ")"); |
|
94
|
|
|
} catch (e) { |
|
95
|
|
|
response = {}; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
if (response.error) { |
|
99
|
|
|
if ((typeof response.message) == "string") { |
|
100
|
|
|
alert(response.message); |
|
101
|
|
|
} else { |
|
102
|
|
|
alert(response.message.join("\n")); |
|
103
|
|
|
} |
|
104
|
|
|
return false; |
|
105
|
|
|
} |
|
106
|
|
|
else { |
|
107
|
|
|
alert(response.status); |
|
108
|
|
|
} |
|
109
|
|
|
}, |
|
110
|
|
|
onSave: function () { |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
//]]> |
|
114
|
|
|
</script>' . "\n"; |
|
115
|
|
|
return $html; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
protected function getSendOrderUrl() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->getFullUrl('send'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
protected function getDeleteOrderUrl() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->getFullUrl('delete'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
protected function getConfirmOrderUrl() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->getFullUrl('confirm'); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
protected function getUpdateOrderUrl() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->getFullUrl('update'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
protected function getLabelUrl() |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->getFullUrl('label'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
protected function getFullUrl($path) |
|
144
|
|
|
{ |
|
145
|
|
|
return Mage::helper('adminhtml')->getUrl('adminhtml/yandexdelivery_api/' . $path, ['_secure' => true, 'orderid' => $this->getOrder()->getId()]); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function getTable() |
|
149
|
|
|
{ |
|
150
|
|
|
//таблица с статусами заказа |
|
151
|
|
|
|
|
152
|
|
|
if (!$this->hasYdId()) { |
|
153
|
|
|
return; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
$result = Mage::getModel('yandexdelivery/carrier')->senderOrderStatuses(Mage::getModel('yandexdelivery/carrier')->getYdId($this->getOrder()->getId())); |
|
157
|
|
|
|
|
158
|
|
|
if ($result->status != "ok") { |
|
159
|
|
|
return; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
$html = '<table class="data order-tables" cellspacing="0">'; |
|
163
|
|
|
$html .= '<colgroup> |
|
164
|
|
|
<col width="1"> |
|
165
|
|
|
<col width="1"> |
|
166
|
|
|
<col width="1"> |
|
167
|
|
|
<col width="1"> |
|
168
|
|
|
</colgroup>'; |
|
169
|
|
|
$html .= '<thead> |
|
170
|
|
|
<tr class="headings"> |
|
171
|
|
|
<th>' . $this->__('Status Date') . '</th> |
|
172
|
|
|
<th>' . $this->__('Description') . '</th> |
|
173
|
|
|
<th>' . $this->__('Uniform status') . '</th> |
|
174
|
|
|
<th>' . $this->__('Status') . '</th> |
|
175
|
|
|
</tr> |
|
176
|
|
|
</thead>'; |
|
177
|
|
|
foreach ($result->data->data as $item) { |
|
178
|
|
|
$html .= '<tbody class="even"> |
|
179
|
|
|
<tr class="border"> |
|
180
|
|
|
<td>' . $item->time . '</td> |
|
181
|
|
|
<td>' . $item->description . '</td> |
|
182
|
|
|
<td>' . $item->uniform_status . '</td> |
|
183
|
|
|
<td>' . $item->status . '</td> |
|
184
|
|
|
</tr> |
|
185
|
|
|
</tbody>'; |
|
186
|
|
|
} |
|
187
|
|
|
$html .= '</table>'; |
|
188
|
|
|
return $html; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.