1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Iris\Api; |
4
|
|
|
|
5
|
|
|
class VentureClient extends BaseClient |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Let the partner know the order was shipped, |
9
|
|
|
* will be changed to allow to inform the status by item |
10
|
|
|
* |
11
|
|
|
* @param string $orderNumber |
12
|
|
|
* @param array $request |
13
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
14
|
|
|
*/ |
15
|
2 |
|
public function shippedOrder($orderNumber, array $request) |
16
|
|
|
{ |
17
|
2 |
|
$response = false; |
18
|
2 |
|
$url = 'api/' . $this->getVersion() . '/order/' . $orderNumber . '/ship'; |
19
|
|
|
|
20
|
|
|
try { |
21
|
2 |
|
$response = $this->update($url, $request); |
22
|
2 |
|
} catch (\Exception $e) { |
23
|
1 |
|
$this->throwException($e, 'Unable to ship order', ['OrderNr' => $orderNumber]); |
24
|
|
|
} |
25
|
|
|
|
26
|
1 |
|
return $response; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Create products on partner |
31
|
|
|
* |
32
|
|
|
* @param \Iris\Transfer\Catalog\ConfigCollection $products |
33
|
|
|
* @param string $partnerCode |
34
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
35
|
|
|
*/ |
36
|
2 |
|
public function createProducts(\Iris\Transfer\Catalog\ConfigCollection $products, $partnerCode) |
37
|
|
|
{ |
38
|
2 |
|
$response = false; |
39
|
2 |
|
$url = 'api/' . $this->getVersion() . '/' . $partnerCode . '/product'; |
40
|
2 |
|
$body = $products->toSimpleArray(); |
41
|
|
|
|
42
|
|
|
try { |
43
|
2 |
|
$response = $this->create($url, $body); |
44
|
2 |
|
} catch (\Exception $e) { |
45
|
1 |
|
$this->throwException($e, 'Unable to create products'); |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
return $response; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Update products on partner |
53
|
|
|
* |
54
|
|
|
* @param \Iris\Transfer\Catalog\ConfigCollection $products |
55
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
56
|
|
|
*/ |
57
|
2 |
|
public function updateProducts(\Iris\Transfer\Catalog\ConfigCollection $products) |
58
|
|
|
{ |
59
|
2 |
|
$response = false; |
60
|
2 |
|
$url = 'api/' . $this->getVersion() . '/product'; |
61
|
2 |
|
$body = $products->toSimpleArray(); |
62
|
|
|
|
63
|
|
|
try { |
64
|
2 |
|
$response = $this->update($url, $body); |
65
|
2 |
|
} catch (\Exception $e) { |
66
|
1 |
|
$this->throwException($e, 'Unable to update products'); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
return $response; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Inform partner to update stock |
74
|
|
|
* |
75
|
|
|
* @param string $sku |
76
|
|
|
* @param integer $quantity |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
2 |
|
public function updateStock($sku, $quantity) |
80
|
|
|
{ |
81
|
2 |
|
$response = false; |
82
|
2 |
|
$url = 'api/' . $this->getVersion() . '/product/' . $sku . '/stock'; |
83
|
2 |
|
$body = ['quantity' => (int) $quantity]; |
84
|
|
|
|
85
|
|
|
try { |
86
|
2 |
|
$response = $this->update($url, $body); |
87
|
2 |
|
} catch (\Exception $e) { |
88
|
1 |
|
$this->throwException($e, 'Unable to update stock', ['Sku' => $sku, 'Quantity' => $quantity]); |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
return $response; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Inform the partner a price update |
96
|
|
|
* |
97
|
|
|
* @param string $sku |
98
|
|
|
* @param float $price |
99
|
|
|
* @param float $specialPrice |
100
|
|
|
* @param string $specialFromDate |
101
|
|
|
* @param string $specialToDate |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
2 |
|
public function updatePrice($sku, $price, $specialPrice, $specialFromDate, $specialToDate) |
105
|
|
|
{ |
106
|
2 |
|
$response = false; |
107
|
2 |
|
$url = 'api/' . $this->getVersion() . '/product/' . $sku . '/price'; |
108
|
|
|
$body = [ |
109
|
2 |
|
'price' => (float) $price, |
110
|
2 |
|
'special_price' => (float) $specialPrice, |
111
|
2 |
|
'special_from_date' => $specialFromDate, |
112
|
|
|
'special_to_date' => $specialToDate |
113
|
2 |
|
]; |
114
|
|
|
|
115
|
|
|
try { |
116
|
2 |
|
$response = $this->update($url, $body); |
117
|
2 |
|
} catch (\Exception $e) { |
118
|
1 |
|
$this->throwException( |
119
|
1 |
|
$e, |
120
|
1 |
|
'Unable to update price', |
121
|
|
|
[ |
122
|
1 |
|
'Sku' => $sku, |
123
|
1 |
|
'Price' => $price, |
124
|
1 |
|
'SpecialPrice' => $specialPrice, |
125
|
1 |
|
'SpecialFromDate' => $specialFromDate, |
126
|
|
|
'SpecialToDate' => $specialToDate |
127
|
1 |
|
] |
128
|
1 |
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
2 |
|
return $response; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param \Iris\Transfer\Tracking\Shipped $status |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
3 |
|
public function setStatusToShipped(\Iris\Transfer\Tracking\Shipped $status) |
139
|
|
|
{ |
140
|
|
|
$bodyData = [ |
141
|
|
|
'items' => [ |
142
|
|
|
[ |
143
|
3 |
|
'venture_order_item_id' => $status->getVentureOrderItemId(), |
144
|
3 |
|
'delivery_type' => $status->getDeliveryType(), |
145
|
3 |
|
'shipping_provider' => $status->getShippingProvider(), |
146
|
3 |
|
'tracking_url' => $status->getTrackingUrl(), |
147
|
3 |
|
'nfe_key' => $status->getNfeKey(), |
148
|
|
|
] |
149
|
3 |
|
] |
150
|
3 |
|
]; |
151
|
|
|
|
152
|
3 |
|
$url = sprintf( |
153
|
3 |
|
'api/%s/order/%s/ship', |
154
|
3 |
|
$this->getVersion(), |
155
|
3 |
|
$status->getVentureOrderNumber() |
156
|
3 |
|
); |
157
|
|
|
|
158
|
|
|
try { |
159
|
3 |
|
$this->update($url, $bodyData); |
160
|
3 |
|
} catch (\Exception $e) { |
161
|
2 |
|
$this->throwException( |
162
|
2 |
|
$e, |
163
|
2 |
|
'Unable to set status to ship', |
164
|
|
|
[ |
165
|
2 |
|
'VentureOrderItemId' => $status->getVentureOrderItemId(), |
166
|
2 |
|
'PartnerCode' => $status->getPartnerCode(), |
167
|
2 |
|
'DeliveryType' => $status->getDeliveryType(), |
168
|
2 |
|
'ShippingProvider' => $status->getShippingProvider(), |
169
|
2 |
|
'TrackingUrl' => $status->getTrackingUrl(), |
170
|
2 |
|
'NfeKey' => $status->getNfeKey(), |
171
|
2 |
|
'VentureOrderNumber' => $status->getVentureOrderNumber(), |
172
|
2 |
|
'Event' => 'tracking-update', |
173
|
2 |
|
'EventType' => 'notify-externalshop-shipped', |
174
|
|
|
] |
175
|
2 |
|
); |
176
|
|
|
|
177
|
1 |
|
return false; |
178
|
|
|
} |
179
|
|
|
|
180
|
1 |
|
return true; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param \Iris\Transfer\Tracking\Delivered $status |
185
|
|
|
* @return bool |
186
|
|
|
*/ |
187
|
3 |
|
public function setStatusToDelivered(\Iris\Transfer\Tracking\Delivered $status) |
188
|
|
|
{ |
189
|
|
|
$bodyData = [ |
190
|
|
|
'items' => [ |
191
|
|
|
[ |
192
|
3 |
|
'venture_order_item_id' => $status->getVentureOrderItemId(), |
193
|
|
|
] |
194
|
3 |
|
] |
195
|
3 |
|
]; |
196
|
|
|
|
197
|
3 |
|
$url = sprintf( |
198
|
3 |
|
'api/%s/order/%s/deliver', |
199
|
3 |
|
$this->getVersion(), |
200
|
3 |
|
$status->getVentureOrderNumber() |
201
|
3 |
|
); |
202
|
|
|
|
203
|
|
|
try { |
204
|
3 |
|
$this->update($url, $bodyData); |
205
|
3 |
|
} catch (\Exception $e) { |
206
|
2 |
|
$this->throwException( |
207
|
2 |
|
$e, |
208
|
2 |
|
'Unable to set status to delivered', |
209
|
|
|
[ |
210
|
2 |
|
'VentureOrderItemId' => $status->getVentureOrderItemId(), |
211
|
2 |
|
'PartnerCode' => $status->getPartnerCode(), |
212
|
2 |
|
'VentureOrderNumber' => $status->getVentureOrderNumber(), |
213
|
2 |
|
'Event' => 'tracking-update', |
214
|
2 |
|
'EventType' => 'notify-externalshop-delivered', |
215
|
|
|
] |
216
|
2 |
|
); |
217
|
|
|
|
218
|
1 |
|
return false; |
219
|
|
|
} |
220
|
|
|
|
221
|
1 |
|
return true; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param \Iris\Transfer\Tracking\FailedDelivery $status |
226
|
|
|
* @return bool |
227
|
|
|
*/ |
228
|
3 |
|
public function setStatusToFailedDelivery(\Iris\Transfer\Tracking\FailedDelivery $status) |
229
|
|
|
{ |
230
|
|
|
$bodyData = [ |
231
|
|
|
'items' => [ |
232
|
|
|
[ |
233
|
3 |
|
'venture_order_item_id' => $status->getVentureOrderItemId(), |
234
|
3 |
|
'reason' => $status->getReason(), |
235
|
3 |
|
'reason_detail' => $status->getReasonDetail(), |
236
|
|
|
] |
237
|
3 |
|
] |
238
|
3 |
|
]; |
239
|
|
|
|
240
|
3 |
|
$url = sprintf( |
241
|
3 |
|
'api/%s/order/%s/failed-delivery', |
242
|
3 |
|
$this->getVersion(), |
243
|
3 |
|
$status->getVentureOrderNumber() |
244
|
3 |
|
); |
245
|
|
|
|
246
|
|
|
try { |
247
|
3 |
|
$this->update($url, $bodyData); |
248
|
3 |
|
} catch (\Exception $e) { |
249
|
2 |
|
$this->throwException( |
250
|
2 |
|
$e, |
251
|
2 |
|
'Unable to set status to failed delivery', |
252
|
|
|
[ |
253
|
2 |
|
'VentureOrderItemId' => $status->getVentureOrderItemId(), |
254
|
2 |
|
'PartnerCode' => $status->getPartnerCode(), |
255
|
2 |
|
'Reason' => $status->getReason(), |
256
|
2 |
|
'ReasonDetail' => $status->getReasonDetail(), |
257
|
2 |
|
'VentureOrderNumber' => $status->getVentureOrderNumber(), |
258
|
2 |
|
'Event' => 'tracking-update', |
259
|
2 |
|
'EventType' => 'notify-externalshop-failed-delivery', |
260
|
|
|
] |
261
|
2 |
|
); |
262
|
|
|
|
263
|
1 |
|
return false; |
264
|
|
|
} |
265
|
|
|
|
266
|
1 |
|
return true; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param \Iris\Transfer\Tracking\Canceled $status |
271
|
|
|
* @throws \RuntimeException Not implemented yet! |
272
|
|
|
*/ |
273
|
|
|
public function setStatusToCanceled(\Iris\Transfer\Tracking\Canceled $status) |
|
|
|
|
274
|
|
|
{ |
275
|
|
|
throw new \RuntimeException('Not implemented yet!'); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.