|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Iris\SaleWrapper; |
|
4
|
|
|
|
|
5
|
|
|
use \Iris\Mapping\Order; |
|
6
|
|
|
|
|
7
|
|
|
class Partner extends Base implements PartnerInterface |
|
8
|
|
|
{ |
|
9
|
|
|
private $mappingClasses; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* {@inheritdoc} |
|
13
|
|
|
*/ |
|
14
|
4 |
|
public function getName() |
|
15
|
|
|
{ |
|
16
|
4 |
|
return 'partner'; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Gets Venture service. |
|
21
|
|
|
* @return \Iris\Interfaces\IrisVenture |
|
22
|
|
|
*/ |
|
23
|
3 |
|
public function getVentureService() |
|
24
|
|
|
{ |
|
25
|
3 |
|
return $this->getManager()->getService(\Iris\Factory::VENTURE); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Gets Stock service. |
|
30
|
|
|
* @return \Iris\Interfaces\Stock |
|
31
|
|
|
*/ |
|
32
|
2 |
|
public function getStockService() |
|
33
|
|
|
{ |
|
34
|
2 |
|
return $this->getManager()->getService(\Iris\Factory::STOCK); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Gets Stock service. |
|
39
|
|
|
* @return \Iris\Interfaces\Catalog |
|
40
|
2 |
|
*/ |
|
41
|
|
|
public function getCatalogService() |
|
42
|
2 |
|
{ |
|
43
|
2 |
|
return $this->getManager()->getService(\Iris\Factory::CATALOG); |
|
44
|
2 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
//order |
|
48
|
|
|
/** |
|
49
|
1 |
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function isVentureItem(\Iris\Transfer\Sales\Order\Item $item) |
|
52
|
|
|
{ |
|
53
|
1 |
|
$irisVenture = $this->getVentureService() |
|
54
|
1 |
|
->getIrisVentureBySalesOrderId($item->getFkSalesOrder()); |
|
55
|
1 |
|
|
|
56
|
1 |
|
return ($irisVenture instanceof \Iris\Transfer\Venture); |
|
57
|
|
|
} |
|
58
|
1 |
|
|
|
59
|
|
|
/** |
|
60
|
1 |
|
* {@inheritdoc} |
|
61
|
1 |
|
*/ |
|
62
|
|
|
public function sendOrderToVenture( |
|
63
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
64
|
|
|
\Iris\Transfer\Venture $venture |
|
65
|
|
|
) { |
|
66
|
1 |
|
$mappedOrder = $this->getOrderMapping()->map($order); |
|
67
|
|
|
|
|
68
|
1 |
|
return $this->getPartnerApiClient() |
|
69
|
1 |
|
->createOrderOnVenture($venture, $mappedOrder); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function dropReserveAndUpdateStock( |
|
76
|
|
|
\Iris\Transfer\Sales\Order\Item $orderItem, |
|
77
|
1 |
|
array $productsData, |
|
78
|
1 |
|
$ventureCode |
|
79
|
|
|
) { |
|
80
|
|
|
$this->getStockService()->dropReserve($orderItem); |
|
81
|
|
|
$this->updateStockFromVenture($productsData, $ventureCode); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
4 |
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
4 |
|
*/ |
|
87
|
|
|
public function confirmOrderPaidOnVenture( |
|
88
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
89
|
|
|
\Iris\Transfer\Venture $venture |
|
90
|
|
|
) { |
|
91
|
|
|
return $this->getPartnerApiClient() |
|
92
|
1 |
|
->confirmPaymentOnVenture( |
|
93
|
|
|
$venture->getVentureCode(), |
|
94
|
1 |
|
$order->getOrderNr() |
|
95
|
|
|
); |
|
96
|
1 |
|
} |
|
97
|
1 |
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
|
|
public function cancelOrderOnVenture( |
|
102
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
103
|
1 |
|
\Iris\Transfer\Venture $venture |
|
104
|
|
|
) { |
|
105
|
1 |
|
return $this->getPartnerApiClient() |
|
106
|
1 |
|
->cancelOrderOnVenture( |
|
107
|
|
|
$venture->getVentureCode(), |
|
108
|
|
|
$order->getOrderNr() |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
1 |
|
/** |
|
113
|
|
|
* {@inheritdoc} |
|
114
|
1 |
|
*/ |
|
115
|
1 |
|
public function cancelOrderFromVenture($orderNr, $ventureCode) |
|
116
|
|
|
{ |
|
117
|
|
|
|
|
118
|
|
|
$order = $this->getOrderService() |
|
119
|
|
|
->getOrderByOrderNumberAndVentureCode($orderNr, $ventureCode); |
|
120
|
|
|
|
|
121
|
1 |
|
$this->getOrderService()->cancelOrderFromVenture($order); |
|
122
|
|
|
return ['order_number' => $order->getOrderNr()]; |
|
123
|
1 |
|
} |
|
124
|
1 |
|
|
|
125
|
1 |
|
/** |
|
126
|
1 |
|
* {@inheritdoc} |
|
127
|
1 |
|
*/ |
|
128
|
1 |
|
public function bindVentureOrder($orderNr, $ventureCode, $ventureorderNr) |
|
129
|
1 |
|
{ |
|
130
|
|
|
$this->getVentureService() |
|
131
|
|
|
->bindPartnerOrderWithVentureOrder( |
|
132
|
|
|
$orderNr, |
|
|
|
|
|
|
133
|
|
|
$ventureCode, |
|
|
|
|
|
|
134
|
|
|
$ventureOrderNr |
|
|
|
|
|
|
135
|
2 |
|
); |
|
136
|
|
|
} |
|
137
|
2 |
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Gets an specific mapping classs |
|
140
|
|
|
* |
|
141
|
|
|
* @param string $mappingName |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getMapping($mappingName) |
|
144
|
|
|
{ |
|
145
|
|
|
if (!$this->mappingClasses[$mappingName]) { |
|
146
|
|
|
$mappingClass = '\Iris\Mapping\\' . $mappingName; |
|
147
|
|
|
$this->mappingClasses[$mappingName] = $mappingClass::getInstance(); |
|
148
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
return $this->mappingClasses[$mappingName]; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Set an specific mapping classs |
|
155
|
|
|
* |
|
156
|
|
|
* @param string $mappingName |
|
157
|
|
|
* @param $mappingClass |
|
158
|
|
|
* @return \Iris\SaleWrapper\Partner |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setMapping($mappingName, $mappingClass) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->mappingClasses[$mappingName] = $mappingClass; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
//tracking |
|
167
|
|
|
/** |
|
168
|
|
|
* {@inheritdoc} |
|
169
|
|
|
*/ |
|
170
|
|
|
public function setOrderStatusToShippedFromVenture(array $orderData) |
|
171
|
|
|
{ |
|
172
|
|
|
$order = $this->getMapping('Order')->assign($orderData); |
|
173
|
|
|
|
|
174
|
|
|
foreach ($order->getItemCollection() as $item) { |
|
175
|
|
|
if (!$item->getTrackingCode()) { |
|
176
|
|
|
$item->setTrackingCode(md5($item->getTrackingUrl())); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
return $this->getOrderService()->shippedByVenture($order); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* {@inheritdoc} |
|
185
|
|
|
*/ |
|
186
|
|
|
public function setOrderStatusToDeliveredFromVenture(array $orderData, $ventureCode) |
|
187
|
|
|
{ |
|
188
|
|
|
$order = $this->getMapping('Order')->assign($orderData); |
|
189
|
|
|
return $this->getOrderService()->deliveredByVenture($order, $ventureCode); |
|
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
//products |
|
193
|
|
|
/** |
|
194
|
|
|
* {@inheritdoc} |
|
195
|
|
|
*/ |
|
196
|
|
|
public function updatePriceFromVenture(array $productsData, $ventureCode) |
|
197
|
|
|
{ |
|
198
|
|
|
$configCollection = $this->getMapping('ConfigCollection')->assign($productsData); |
|
199
|
|
|
return $this->getCatalogService()->updatePrice($configCollection); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* {@inheritdoc} |
|
204
|
|
|
*/ |
|
205
|
|
|
public function updateStockFromVenture(array $productsData, $ventureCode) |
|
206
|
|
|
{ |
|
207
|
|
|
$configCollection = $this->getMapping('SimpleCollection')->assign($productsData); |
|
208
|
|
|
return $this->getStockService()->updateAbsoluteStock($configCollection); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* {@inheritdoc} |
|
213
|
|
|
*/ |
|
214
|
|
|
public function createProductsFromVenture(array $productsData, $ventureCode) |
|
215
|
|
|
{ |
|
216
|
|
|
$configCollection = \Iris\Mapping\ConfigCollection::assign($productsData); |
|
217
|
|
|
return $this->getCatalogService()->createProducts($configCollection, $ventureCode); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* {@inheritdoc} |
|
222
|
|
|
*/ |
|
223
|
|
|
public function sendProductCreationConfirmationToVenture( |
|
224
|
|
|
\Iris\Transfer\Catalog\ConfigCollection $configCollection, |
|
225
|
|
|
\Iris\Transfer\Venture $venture |
|
226
|
|
|
) { |
|
227
|
|
|
$productsData = \Iris\Mapping\ConfigCollection::map($configCollection); |
|
228
|
|
|
$this->getPartnerApiClient() |
|
229
|
|
|
->sendProductCreationConfirmationToVenture( |
|
230
|
|
|
$productsData, |
|
231
|
|
|
$venture->getVentureCode() |
|
232
|
|
|
); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* {@inheritdoc} |
|
237
|
|
|
*/ |
|
238
|
|
|
public function updateProductsFromVenture(array $productsData, $ventureCode) |
|
239
|
|
|
{ |
|
240
|
|
|
$configCollection = \Iris\Mapping\ConfigCollection::assign($productsData); |
|
241
|
|
|
return $this->getCatalogService()->updateProducts($configCollection, $ventureCode); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* {@inheritdoc} |
|
246
|
|
|
*/ |
|
247
|
|
|
public function updateProductImagesFromVenture(array $productsData, $ventureCode) |
|
248
|
|
|
{ |
|
249
|
|
|
$configCollection = \Iris\Mapping\ConfigCollection::assign($productsData); |
|
250
|
|
|
return $this->getCatalogService()->updateImages($configCollection, $ventureCode); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* {@inheritdoc} |
|
255
|
|
|
*/ |
|
256
|
|
|
public function shippedOrder( |
|
257
|
|
|
\Iris\Transfer\Sales\Order $order, |
|
258
|
|
|
\Iris\Transfer\Venture $venture |
|
259
|
|
|
) { |
|
260
|
|
|
$itemsRequested = $this->getOrderItems($order); |
|
|
|
|
|
|
261
|
|
|
|
|
262
|
|
|
$salesOrder = $this->getOrderService() |
|
263
|
|
|
->getOrderByOrderNumberAndOrderItemsAndVentureCode( |
|
264
|
|
|
$order->getOrderNr(), |
|
265
|
|
|
$itemsRequested, |
|
266
|
|
|
$venture->getVentureCode() |
|
267
|
|
|
); |
|
268
|
|
|
|
|
269
|
|
|
foreach ($order->getItemCollection() as $item) { |
|
270
|
|
|
if (!$item->getTrackingCode()) { |
|
271
|
|
|
$item->setTrackingCode(md5($item->getTrackingUrl())); |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
return $this->getOrderService()->shippedByVenture($salesOrder); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* {@inheritdoc} |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setOrderStatusToDeliveryFailedFromVenture( |
|
282
|
|
|
array $orderData, |
|
283
|
|
|
$ventureCode |
|
284
|
|
|
) { |
|
285
|
|
|
$order = $this->getMapping('Order')->assign($orderData); |
|
286
|
|
|
return $this->getOrderService() |
|
287
|
|
|
->deliveryFailedByVenture($order, $ventureCode); |
|
|
|
|
|
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* {@inheritdoc} |
|
292
|
|
|
*/ |
|
293
|
|
|
public function isInvalidOrder(\Iris\Transfer\Sales\Order $order) |
|
294
|
|
|
{ |
|
295
|
|
|
return $this->getOrderService()->isInvalidOrder($order); |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: