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