1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Iris\Api; |
4
|
|
|
|
5
|
|
|
class VentureClient extends BaseClient |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Create products on partner |
9
|
|
|
* |
10
|
|
|
* @param \Iris\Transfer\Catalog\ConfigCollection $products |
11
|
|
|
* @param string $partnerCode |
12
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
13
|
|
|
*/ |
14
|
|
|
public function createProducts(\Iris\Transfer\Catalog\ConfigCollection $products, $partnerCode) |
15
|
2 |
|
{ |
16
|
|
|
$response = false; |
17
|
2 |
|
$url = 'api/' . $this->getVersion() . '/' . $partnerCode . '/product'; |
18
|
2 |
|
$body = $products->toSimpleArray(); |
19
|
2 |
|
|
20
|
|
|
try { |
21
|
|
|
$response = $this->create($url, $body); |
22
|
2 |
|
} catch (\Exception $e) { |
23
|
2 |
|
$this->throwException($e, 'Unable to create products'); |
24
|
1 |
|
} |
25
|
|
|
|
26
|
|
|
return $response; |
27
|
1 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Update products on partner |
31
|
|
|
* |
32
|
|
|
* @param \Iris\Transfer\Catalog\ConfigCollection $products |
33
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
34
|
|
|
*/ |
35
|
|
|
public function updateProducts(\Iris\Transfer\Catalog\ConfigCollection $products) |
36
|
2 |
|
{ |
37
|
|
|
$response = false; |
38
|
2 |
|
$url = 'api/' . $this->getVersion() . '/product'; |
39
|
2 |
|
$body = $products->toSimpleArray(); |
40
|
2 |
|
|
41
|
|
|
try { |
42
|
|
|
$response = $this->update($url, $body); |
43
|
2 |
|
} catch (\Exception $e) { |
44
|
2 |
|
$this->throwException($e, 'Unable to update products'); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
|
return $response; |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Inform partner to update stock |
52
|
|
|
* |
53
|
|
|
* @param string $sku |
54
|
|
|
* @param integer $quantity |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public function updateStock($sku, $quantity) |
58
|
2 |
|
{ |
59
|
|
|
$response = false; |
60
|
2 |
|
$url = 'api/' . $this->getVersion() . '/product/' . $sku . '/stock'; |
61
|
2 |
|
$body = ['quantity' => (int) $quantity]; |
62
|
2 |
|
|
63
|
|
|
try { |
64
|
|
|
$response = $this->update($url, $body); |
65
|
2 |
|
} catch (\Exception $e) { |
66
|
2 |
|
$this->throwException($e, 'Unable to update stock', ['Sku' => $sku, 'Quantity' => $quantity]); |
67
|
1 |
|
} |
68
|
|
|
|
69
|
|
|
return $response; |
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Inform the partner a price update |
74
|
|
|
* |
75
|
|
|
* @param string $sku |
76
|
|
|
* @param float $price |
77
|
|
|
* @param float $specialPrice |
78
|
|
|
* @param string $specialFromDate |
79
|
|
|
* @param string $specialToDate |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
|
|
public function updatePrice($sku, $price, $specialPrice, $specialFromDate, $specialToDate) |
83
|
2 |
|
{ |
84
|
|
|
$response = false; |
85
|
2 |
|
$url = 'api/' . $this->getVersion() . '/product/' . $sku . '/price'; |
86
|
2 |
|
$body = [ |
87
|
|
|
'price' => (float) $price, |
88
|
2 |
|
'special_price' => (float) $specialPrice, |
89
|
2 |
|
'special_from_date' => $specialFromDate, |
90
|
2 |
|
'special_to_date' => $specialToDate |
91
|
|
|
]; |
92
|
2 |
|
|
93
|
|
|
try { |
94
|
|
|
$response = $this->update($url, $body); |
95
|
2 |
|
} catch (\Exception $e) { |
96
|
2 |
|
$this->throwException( |
97
|
1 |
|
$e, |
98
|
1 |
|
'Unable to update price', |
99
|
1 |
|
[ |
100
|
|
|
'Sku' => $sku, |
101
|
1 |
|
'Price' => $price, |
102
|
1 |
|
'SpecialPrice' => $specialPrice, |
103
|
1 |
|
'SpecialFromDate' => $specialFromDate, |
104
|
1 |
|
'SpecialToDate' => $specialToDate |
105
|
|
|
] |
106
|
1 |
|
); |
107
|
1 |
|
} |
108
|
|
|
|
109
|
|
|
return $response; |
110
|
2 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param \Iris\Transfer\Tracking\ShippedCollection $items |
114
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
115
|
|
|
*/ |
116
|
|
|
public function setStatusToShippedOnPartner(\Iris\Transfer\Tracking\ShippedCollection $items) |
117
|
2 |
|
{ |
118
|
|
|
$response = false; |
119
|
2 |
|
$bodyData = []; |
120
|
2 |
|
|
121
|
|
|
foreach ($items as $item) { |
122
|
2 |
|
$bodyData['items'][] = [ |
123
|
2 |
|
'venture_order_item_id' => $item->getVentureOrderItemId(), |
124
|
2 |
|
'delivery_type' => $item->getDeliveryType(), |
125
|
2 |
|
'shipping_provider' => $item->getShippingProvider(), |
126
|
2 |
|
'tracking_url' => $item->getTrackingUrl(), |
127
|
2 |
|
'nfe_key' => $item->getNfeKey() |
128
|
2 |
|
]; |
129
|
2 |
|
} |
130
|
2 |
|
|
131
|
|
|
$url = sprintf( |
132
|
2 |
|
'api/%s/order/%s/ship', |
133
|
2 |
|
$this->getVersion(), |
134
|
2 |
|
$items[0]->getVentureOrderNumber() |
135
|
2 |
|
); |
136
|
2 |
|
|
137
|
|
|
try { |
138
|
|
|
$response = $this->update($url, $bodyData); |
139
|
2 |
|
} catch (\Exception $e) { |
140
|
2 |
|
$this->throwException( |
141
|
1 |
|
$e, |
142
|
1 |
|
'Unable to set status to ship', |
143
|
1 |
|
[ |
144
|
|
|
'VentureOrderItemId' => $items[0]->getVentureOrderItemId(), |
145
|
1 |
|
'PartnerCode' => $items[0]->getPartnerCode(), |
146
|
1 |
|
'DeliveryType' => $items[0]->getDeliveryType(), |
147
|
1 |
|
'ShippingProvider' => $items[0]->getShippingProvider(), |
148
|
1 |
|
'TrackingUrl' => $items[0]->getTrackingUrl(), |
149
|
1 |
|
'NfeKey' => $items[0]->getNfeKey(), |
150
|
1 |
|
'VentureOrderNumber' => $items[0]->getVentureOrderNumber(), |
151
|
1 |
|
'Event' => 'tracking-update', |
152
|
1 |
|
'EventType' => 'notify-externalshop-shipped' |
153
|
|
|
] |
154
|
1 |
|
); |
155
|
1 |
|
} |
156
|
|
|
|
157
|
|
|
return $response; |
158
|
2 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param \Iris\Transfer\Tracking\DeliveredCollection $items |
162
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
163
|
|
|
*/ |
164
|
|
|
public function setStatusToDeliveredOnPartner(\Iris\Transfer\Tracking\DeliveredCollection $items) |
165
|
2 |
|
{ |
166
|
|
|
$response = false; |
167
|
2 |
|
$bodyData = []; |
168
|
2 |
|
|
169
|
|
|
foreach ($items as $item) { |
170
|
2 |
|
$bodyData['items'][] = [ |
171
|
2 |
|
'venture_order_item_id' => $item->getVentureOrderItemId() |
172
|
2 |
|
]; |
173
|
2 |
|
} |
174
|
2 |
|
|
175
|
|
|
$url = sprintf( |
176
|
2 |
|
'api/%s/order/%s/deliver', |
177
|
2 |
|
$this->getVersion(), |
178
|
2 |
|
$items[0]->getVentureOrderNumber() |
179
|
2 |
|
); |
180
|
2 |
|
|
181
|
|
|
try { |
182
|
|
|
$response = $this->update($url, $bodyData); |
183
|
2 |
|
} catch (\Exception $e) { |
184
|
2 |
|
$this->throwException( |
185
|
1 |
|
$e, |
186
|
1 |
|
'Unable to set status to delivered', |
187
|
1 |
|
[ |
188
|
|
|
'VentureOrderItemId' => $items[0]->getVentureOrderItemId(), |
189
|
1 |
|
'PartnerCode' => $items[0]->getPartnerCode(), |
190
|
1 |
|
'VentureOrderNumber' => $items[0]->getVentureOrderNumber(), |
191
|
1 |
|
'Event' => 'tracking-update', |
192
|
1 |
|
'EventType' => 'notify-externalshop-delivered' |
193
|
|
|
] |
194
|
1 |
|
); |
195
|
1 |
|
} |
196
|
|
|
|
197
|
|
|
return $response; |
198
|
2 |
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param \Iris\Transfer\Tracking\FailedDeliveryCollection $items |
202
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
203
|
|
|
*/ |
204
|
|
|
public function setStatusToFailedDeliveryOnPartner(\Iris\Transfer\Tracking\FailedDeliveryCollection $items) |
205
|
2 |
|
{ |
206
|
|
|
$response = false; |
207
|
2 |
|
$bodyData = []; |
208
|
2 |
|
|
209
|
|
|
foreach ($items as $item) { |
210
|
2 |
|
$bodyData['items'][] = [ |
211
|
2 |
|
'venture_order_item_id' => $item->getVentureOrderItemId(), |
212
|
2 |
|
'reason' => $item->getReason(), |
213
|
2 |
|
'reason_detail' => $item->getReasonDetail() |
214
|
2 |
|
]; |
215
|
2 |
|
} |
216
|
2 |
|
|
217
|
|
|
$url = sprintf( |
218
|
2 |
|
'api/%s/order/%s/failed-delivery', |
219
|
2 |
|
$this->getVersion(), |
220
|
2 |
|
$items[0]->getVentureOrderNumber() |
221
|
2 |
|
); |
222
|
2 |
|
|
223
|
|
|
try { |
224
|
|
|
$response = $this->update($url, $bodyData); |
225
|
2 |
|
} catch (\Exception $e) { |
226
|
2 |
|
$this->throwException( |
227
|
1 |
|
$e, |
228
|
1 |
|
'Unable to set status to failed delivery', |
229
|
1 |
|
[ |
230
|
|
|
'VentureOrderItemId' => $items[0]->getVentureOrderItemId(), |
231
|
1 |
|
'PartnerCode' => $items[0]->getPartnerCode(), |
232
|
1 |
|
'Reason' => $items[0]->getReason(), |
233
|
1 |
|
'ReasonDetail' => $items[0]->getReasonDetail(), |
234
|
1 |
|
'VentureOrderNumber' => $items[0]->getVentureOrderNumber(), |
235
|
1 |
|
'Event' => 'tracking-update', |
236
|
1 |
|
'EventType' => 'notify-externalshop-failed-delivery' |
237
|
|
|
] |
238
|
1 |
|
); |
239
|
1 |
|
} |
240
|
|
|
|
241
|
|
|
return $response; |
242
|
2 |
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @param \Iris\Transfer\Tracking\CanceledCollection $items |
246
|
|
|
* @return bool|\GuzzleHttp\Message\Response |
247
|
|
|
*/ |
248
|
|
|
public function setStatusToCanceledOnPartner(\Iris\Transfer\Tracking\CanceledCollection $items) |
249
|
2 |
|
{ |
250
|
|
|
$response = false; |
251
|
2 |
|
$bodyData = []; |
252
|
2 |
|
|
253
|
|
|
foreach ($items as $item) { |
254
|
2 |
|
$bodyData['items'][] = [ |
255
|
2 |
|
'venture_order_item_id' => $item->getVentureOrderItemId(), |
256
|
2 |
|
'reason' => $item->getReason(), |
257
|
2 |
|
'reason_detail' => $item->getReasonDetail() |
258
|
2 |
|
]; |
259
|
2 |
|
} |
260
|
2 |
|
|
261
|
|
|
$url = sprintf( |
262
|
2 |
|
'api/%s/order/%s/cancel', |
263
|
2 |
|
$this->getVersion(), |
264
|
2 |
|
$items[0]->getVentureOrderNumber() |
265
|
2 |
|
); |
266
|
2 |
|
|
267
|
|
|
try { |
268
|
|
|
$response = $this->update($url, $bodyData); |
269
|
2 |
|
} catch (\Exception $e) { |
270
|
2 |
|
$this->throwException( |
271
|
1 |
|
$e, |
272
|
1 |
|
'Unable to set status to cancel', |
273
|
1 |
|
[ |
274
|
|
|
'VentureOrderItemId' => $items[0]->getVentureOrderItemId(), |
275
|
1 |
|
'PartnerCode' => $items[0]->getPartnerCode(), |
276
|
1 |
|
'Reason' => $items[0]->getReason(), |
277
|
1 |
|
'ReasonDetail' => $items[0]->getReasonDetail(), |
278
|
1 |
|
'VentureOrderNumber' => $items[0]->getVentureOrderNumber(), |
279
|
1 |
|
'Event' => 'tracking-update', |
280
|
1 |
|
'EventType' => 'notify-externalshop-cancelled' |
281
|
|
|
] |
282
|
1 |
|
); |
283
|
1 |
|
} |
284
|
|
|
|
285
|
|
|
return $response; |
286
|
2 |
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* undocumented function |
290
|
|
|
* |
291
|
|
|
* @return void |
292
|
|
|
*/ |
293
|
|
|
public function confirmOrderOnPartner( |
294
|
|
|
\Iris\Transfer\Sales\Order $order, |
295
|
|
|
$partnerCode |
296
|
|
|
) { |
297
|
|
|
$response = false; |
|
|
|
|
298
|
|
|
$bodyData = [ |
299
|
|
|
'order_nr' => $order->getOrderNr(), |
300
|
|
|
'items' => [] |
301
|
|
|
]; |
302
|
|
|
|
303
|
|
|
foreach ($order->getItemCollection() as $item) { |
304
|
|
|
$bodyData['items'][] = [ |
305
|
|
|
'id_sales_order_item' => $item->getIdSalesOrderItem(), |
306
|
|
|
'sku' => $item->getSku(), |
307
|
|
|
'quantity' => $item->getQuantity(), |
308
|
|
|
'status' => true |
309
|
|
|
]; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
$url = sprintf( |
313
|
|
|
'/api/%s/order/%s/confirm', |
314
|
|
|
$this->getVersion(), |
315
|
|
|
$order->getOrderNr() |
316
|
|
|
); |
317
|
|
|
|
318
|
|
|
try { |
319
|
|
|
$response = $this->update($url, $bodyData); |
|
|
|
|
320
|
|
|
} catch (\Exception $e) { |
321
|
|
|
$this->throwException( |
322
|
|
|
$e, |
323
|
|
|
'Unable to set status to cancel', |
324
|
|
|
[ |
325
|
|
|
'OrderNr' => $order->getOrderNr(), |
326
|
|
|
'PartnerCode' => $partnerCode |
327
|
|
|
] |
328
|
|
|
); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.