|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Iris\SaleWrapper; |
|
4
|
|
|
|
|
5
|
|
|
class Partner extends Base implements PartnerInterface |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Gets Venture service. |
|
9
|
|
|
* @return Iris\Interfaces\IrisVenture |
|
10
|
|
|
*/ |
|
11
|
|
|
public function getVentureService() |
|
12
|
|
|
{ |
|
13
|
|
|
return $this->getManager()->getService(\Iris\Factory::VENTURE); |
|
14
|
4 |
|
} |
|
15
|
|
|
|
|
16
|
4 |
|
/** |
|
17
|
|
|
* Gets Stock service. |
|
18
|
|
|
* @return Iris\Interfaces\Stock |
|
19
|
|
|
*/ |
|
20
|
|
|
public function getStockService() |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->getManager()->getService(\Iris\Factory::STOCK); |
|
23
|
3 |
|
} |
|
24
|
|
|
|
|
25
|
3 |
|
/** |
|
26
|
|
|
* Gets Stock service. |
|
27
|
|
|
* @return Iris\Interfaces\Catalog |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getCatalogService() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getManager()->getService(\Iris\Factory::CATALOG); |
|
32
|
2 |
|
} |
|
33
|
|
|
|
|
34
|
2 |
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
public function confirmReserveAndUpdateStock( |
|
38
|
|
|
\Iris\Transfer\Sales\Order\Item $orderItem |
|
39
|
|
|
\Iris\Transfer\Catalog\Simple $product |
|
|
|
|
|
|
40
|
2 |
|
) { |
|
41
|
|
|
$this->getStockService()->dropReserve($orderItem); |
|
42
|
2 |
|
$this->updateStockFromVenture($product); |
|
43
|
2 |
|
} |
|
44
|
2 |
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
public function isVentureItem(\Iris\Transfer\Sales\Order\Item $item) |
|
49
|
1 |
|
{ |
|
50
|
|
|
$irisVenture = $this->getVentureService() |
|
51
|
1 |
|
->getIrisVentureBySalesOrderId($item->getFkSalesOrder()); |
|
52
|
|
|
|
|
53
|
1 |
|
return ($irisVenture instanceof \Iris\Transfer\Venture); |
|
54
|
1 |
|
} |
|
55
|
1 |
|
|
|
56
|
1 |
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
1 |
|
*/ |
|
59
|
|
|
public function sendOrderToVenture( |
|
60
|
1 |
|
\Iris\Transfer\Sales\Order $order, |
|
61
|
1 |
|
\Iris\Transfer\Venture $venture |
|
62
|
|
|
) { |
|
63
|
|
|
$mappedOrder = $this->getOrderMapping()->map($order); |
|
64
|
|
|
|
|
65
|
|
|
return $this->getPartnerApiClient() |
|
66
|
1 |
|
->createOrderOnVenture($venture, $mappedOrder); |
|
67
|
|
|
} |
|
68
|
1 |
|
|
|
69
|
1 |
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
|
|
public function confirmOrderPaidOnVenture( |
|
73
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
74
|
|
|
\Iris\Transfer\Venture $venture |
|
75
|
1 |
|
) { |
|
76
|
|
|
return $this->getPartnerApiClient() |
|
77
|
1 |
|
->confirmPaymentForVenture( |
|
78
|
1 |
|
$venture->getVentureCode(), |
|
79
|
|
|
$order->getOrderNr() |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
4 |
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
86
|
4 |
|
public function cancelOrderOnVenture( |
|
87
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
88
|
|
|
\Iris\Transfer\Venture $venture |
|
89
|
|
|
) { |
|
90
|
|
|
return $this->getPartnerApiClient() |
|
91
|
|
|
->cancelOrderOnVenture( |
|
92
|
1 |
|
$venture->getVentureCode(), |
|
93
|
|
|
$order->getOrderNr() |
|
94
|
1 |
|
); |
|
95
|
|
|
} |
|
96
|
1 |
|
|
|
97
|
1 |
|
/** |
|
98
|
|
|
* {@inheritdoc} |
|
99
|
|
|
*/ |
|
100
|
|
|
public function cancelOrderFromVenture( |
|
101
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
102
|
|
|
\Iris\Transfer\Venture $venture |
|
103
|
1 |
|
) { |
|
104
|
|
|
$this->getOrderService()->cancel($order); |
|
105
|
1 |
|
return ['order_number' => $order->getOrderNr()]; |
|
106
|
1 |
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* {@inheritdoc} |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getName() |
|
112
|
1 |
|
{ |
|
113
|
|
|
return 'partner'; |
|
114
|
1 |
|
} |
|
115
|
1 |
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* {@inheritdoc} |
|
118
|
|
|
*/ |
|
119
|
|
|
public function shippedOrder( |
|
120
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
121
|
1 |
|
\Iris\Transfer\Venture $venture |
|
122
|
|
|
) { |
|
123
|
1 |
|
$itemsRequestedToBeShipped = $this->getOrderItems($order); |
|
124
|
1 |
|
|
|
125
|
1 |
|
$salesOrder = $this->getOrderService() |
|
126
|
1 |
|
->getOrderByOrderNumberAndOrderItemsAndVentureCode( |
|
127
|
1 |
|
$order->getOrderNr(), |
|
128
|
1 |
|
$itemsRequestedToBeShipped, |
|
129
|
1 |
|
$venture->getVentureCode() |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
$salesOrder = $this->updateItemsWithTheIncomingData( |
|
133
|
|
|
$salesOrder, |
|
134
|
|
|
$order->getItemCollection() |
|
135
|
2 |
|
); |
|
136
|
|
|
|
|
137
|
2 |
|
return $this->getOrderService()->shippedByVenture($salesOrder); |
|
138
|
|
|
} |
|
139
|
|
|
/** |
|
140
|
|
|
* {@inheritdoc} |
|
141
|
|
|
*/ |
|
142
|
|
|
public function deliveredOrder( |
|
143
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
144
|
|
|
\Iris\Transfer\Venture $venture |
|
145
|
|
|
) { |
|
146
|
|
|
$itemsRequestedToBeDelivery = $this->getOrderItems($order); |
|
147
|
|
|
|
|
148
|
|
|
$salesOrder = $this->getOrderService() |
|
149
|
|
|
->getOrderByOrderNumberAndOrderItemsAndVentureCode( |
|
150
|
|
|
$order->getOrderNr(), |
|
151
|
|
|
$itemsRequestedToBeDelivery, |
|
152
|
|
|
$venture->getVentureCode() |
|
153
|
|
|
); |
|
154
|
|
|
|
|
155
|
|
|
return $this->getOrderService()->deliveredByVenture($salesOrder); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* {@inheritdoc} |
|
160
|
|
|
*/ |
|
161
|
|
|
public function deliveryFailedOrder( |
|
162
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
163
|
|
|
\Iris\Transfer\Venture $venture |
|
164
|
|
|
) { |
|
165
|
|
|
$itemsRequestedToBeDeliveryFailed = $this->getOrderItems($order); |
|
166
|
|
|
|
|
167
|
|
|
$salesOrder = $this->getOrderService() |
|
168
|
|
|
->getOrderByOrderNumberAndOrderItemsAndVentureCode( |
|
169
|
|
|
$order->getOrderNr(), |
|
170
|
|
|
$itemsRequestedToBeDeliveryFailed, |
|
171
|
|
|
$venture->getVentureCode() |
|
172
|
|
|
); |
|
173
|
|
|
|
|
174
|
|
|
return $this->getOrderService()->deliveryFailedByVenture($salesOrder); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* {@inheritdoc} |
|
179
|
|
|
*/ |
|
180
|
|
|
public function setNfeKey( |
|
181
|
|
|
$orderNumber, |
|
182
|
|
|
\Iris\Transfer\Sales\Order\ItemCollection $items, |
|
183
|
|
|
$ventureCode |
|
184
|
|
|
) { |
|
185
|
|
|
foreach ($items as $item) { |
|
186
|
|
|
$this->getOrderService() |
|
187
|
|
|
->setNFeKeyForItem( |
|
188
|
|
|
$orderNumber, |
|
189
|
|
|
$ventureCode, |
|
190
|
|
|
$item->getIdSalesOrderItem(), |
|
191
|
|
|
$item->getNfeKey() |
|
192
|
|
|
); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* {@inheritdoc} |
|
198
|
|
|
*/ |
|
199
|
|
|
public function setNfeKeyAndTrackingUrl(\Iris\Transfer\Sales\Order $order, $originCode) |
|
200
|
|
|
{ |
|
201
|
|
|
$itemsRequested = $this->getOrderItems($order); |
|
202
|
|
|
$venture = $this->getVentureService()->findByCode($originCode); |
|
203
|
|
|
$orderService = $this->getOrderService(); |
|
204
|
|
|
|
|
205
|
|
|
$salesOrder = $orderService->getOrderByOrderNumberAndOrderItemsAndVentureCode( |
|
206
|
|
|
$order->getOrderNr(), |
|
207
|
|
|
$itemsRequested, |
|
208
|
|
|
$venture->getVentureCode() |
|
209
|
|
|
); |
|
210
|
|
|
|
|
211
|
|
|
$orderItemCollection = $order->getItemCollection(); |
|
212
|
|
|
|
|
213
|
|
|
foreach ($orderItemCollection as $item) { |
|
214
|
|
|
$data = [ |
|
215
|
|
|
'nfe_key' => $item->getNfeKey(), |
|
216
|
|
|
'tracking_url' => $item->getTrackingUrl(), |
|
217
|
|
|
'tracking_code' => md5($item->getTrackingUrl()), |
|
218
|
|
|
]; |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @todo When ExternalShop starts to send the tracking_code key we |
|
222
|
|
|
* must put this as required and not more as optionally. |
|
223
|
|
|
*/ |
|
224
|
|
|
if ($item->getTrackingCode()) { |
|
225
|
|
|
$data['tracking_code'] = $item->getTrackingCode(); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
$orderService->updateItem( |
|
229
|
|
|
$salesOrder->getIdSalesOrder(), |
|
230
|
|
|
$venture->getVentureCode(), |
|
231
|
|
|
$item->getIdSalesOrderItem(), |
|
232
|
|
|
$data |
|
233
|
|
|
); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* {@inheritdoc} |
|
239
|
|
|
*/ |
|
240
|
|
|
public function isInvalidOrder(\Iris\Transfer\Sales\Order $order) |
|
241
|
|
|
{ |
|
242
|
|
|
return $this->getOrderService()->isInvalidOrder($order); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* @param Iris\Transfer\Sales\Order $order |
|
247
|
|
|
* @return array |
|
248
|
|
|
*/ |
|
249
|
|
|
private function getOrderItems(\Iris\Transfer\Sales\Order $order) |
|
250
|
|
|
{ |
|
251
|
|
|
$orderItems = []; |
|
252
|
|
|
$orderItemCollection = $order->getItemCollection(); |
|
253
|
|
|
|
|
254
|
|
|
foreach ($orderItemCollection as $item) { |
|
255
|
|
|
$orderItems[] = $item->getIdSalesOrderItem(); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
return $orderItems; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* @param Iris\Transfer\Sales\Order $order |
|
263
|
|
|
* @param Iris\Trnasfer\Sales\Order\ItemsCollection $items |
|
264
|
|
|
* @return Iris\Transfer\Sales\Order |
|
265
|
|
|
*/ |
|
266
|
|
|
private function updateItemsWithTheIncomingData( |
|
267
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
268
|
|
|
\Iris\Transfer\Sales\Order\ItemCollection $items |
|
269
|
|
|
) { |
|
270
|
|
|
foreach ($items as $item) { |
|
271
|
|
|
|
|
272
|
|
|
$orderItem = $order->getItemCollection()->offsetGet($item->getIdSalesOrderItem()); |
|
273
|
|
|
|
|
274
|
|
|
if (!empty($item->getTrackingUrl())) { |
|
275
|
|
|
$this->getOrderService()->setTrackingUrl( |
|
276
|
|
|
$orderItem, |
|
277
|
|
|
$item->getTrackingUrl() |
|
278
|
|
|
); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
if (!empty($item->getNfeKey())) { |
|
282
|
|
|
$orderItem->setDanfeId($item->getNfeKey()); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
if (!empty($item->getTrackingCode())) { |
|
286
|
|
|
$orderItem->setTracking($item->getTrackingCode()); |
|
287
|
|
|
} else { |
|
288
|
|
|
$orderItem->setTracking(md5($item->getTrackingUrl())); |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
return $order; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* {@inheritdoc} |
|
297
|
|
|
*/ |
|
298
|
|
|
public function bindVentureOrder($orderNumber, $ventureCode, $ventureOrderNumber) |
|
299
|
|
|
{ |
|
300
|
|
|
$venture = $this->getVentureService()->findByCode($ventureCode); |
|
301
|
|
|
|
|
302
|
|
|
$order = $this->getOrderService() |
|
303
|
|
|
->getOrderByOrderNumberAndVentureCode( |
|
304
|
|
|
$orderNumber, |
|
305
|
|
|
$venture->getVentureCode() |
|
306
|
|
|
); |
|
307
|
|
|
|
|
308
|
|
|
$this->getVentureService() |
|
309
|
|
|
->bindPartnerOrderWithVentureOrder( |
|
310
|
|
|
$order, |
|
311
|
|
|
$venture, |
|
312
|
|
|
$ventureOrderNumber |
|
313
|
|
|
); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* {@inheritdoc} |
|
318
|
|
|
*/ |
|
319
|
|
|
public function updatePriceFromVenture(\Iris\Transfer\Config $product) |
|
320
|
|
|
{ |
|
321
|
|
|
return $this->getCatalogService()->updatePrice( |
|
322
|
|
|
$product->getSku(), |
|
323
|
|
|
$product->getPrice(), |
|
324
|
|
|
$product->getSpecialPrice(), |
|
325
|
|
|
$prodcut->getSpecialFromDate(), |
|
326
|
|
|
$product->getSpecialToDate() |
|
327
|
|
|
); |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* {@inheritdoc} |
|
332
|
|
|
*/ |
|
333
|
|
|
public function updateStockFromVenture(\Iris\Transfer\Catalog\Simple $product) |
|
334
|
|
|
{ |
|
335
|
|
|
return $this->getStockService() |
|
336
|
|
|
->updateAbsoluteStock($product->getSku(), $product->getQuantity()); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* {@inheritdoc} |
|
341
|
|
|
*/ |
|
342
|
|
|
public function createProductsFromVenture( |
|
343
|
|
|
\Iris\Transfer\Catalog\ConfigCollection $products, |
|
344
|
|
|
\Iris\Transfer\Venture $venture |
|
345
|
|
|
) { |
|
346
|
|
|
//@todo |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* {@inheritdoc} |
|
351
|
|
|
*/ |
|
352
|
|
|
public function updateProductsFromVenture( |
|
353
|
|
|
\Iris\Transfer\Catalog\ConfigCollection $products, |
|
354
|
|
|
\Iris\Transfer\Venture $venture |
|
355
|
|
|
) { |
|
356
|
|
|
//@todo |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* {@inheritdoc} |
|
361
|
|
|
*/ |
|
362
|
|
|
private function handleImages( |
|
363
|
|
|
\Iris\Transfer\Catalog\Config $config, |
|
364
|
|
|
\Iris\Transfer\Catalog\ImageCollection $images |
|
365
|
|
|
) { |
|
366
|
|
|
//@todo |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
|