|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Spryker\Zed\Shipment\Persistence; |
|
9
|
|
|
|
|
10
|
|
|
use ArrayObject; |
|
11
|
|
|
use Generated\Shared\Transfer\ItemTransfer; |
|
12
|
|
|
use Generated\Shared\Transfer\OrderTransfer; |
|
13
|
|
|
use Generated\Shared\Transfer\PaginationTransfer; |
|
14
|
|
|
use Generated\Shared\Transfer\SalesShipmentCollectionTransfer; |
|
15
|
|
|
use Generated\Shared\Transfer\SalesShipmentCriteriaTransfer; |
|
16
|
|
|
use Generated\Shared\Transfer\ShipmentCarrierRequestTransfer; |
|
17
|
|
|
use Generated\Shared\Transfer\ShipmentCarrierTransfer; |
|
18
|
|
|
use Generated\Shared\Transfer\ShipmentMethodCollectionTransfer; |
|
19
|
|
|
use Generated\Shared\Transfer\ShipmentMethodCriteriaTransfer; |
|
20
|
|
|
use Generated\Shared\Transfer\ShipmentMethodTransfer; |
|
21
|
|
|
use Generated\Shared\Transfer\ShipmentPriceTransfer; |
|
22
|
|
|
use Generated\Shared\Transfer\ShipmentTransfer; |
|
23
|
|
|
use Generated\Shared\Transfer\StoreRelationTransfer; |
|
24
|
|
|
use Generated\Shared\Transfer\TaxSetTransfer; |
|
25
|
|
|
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderItemTableMap; |
|
26
|
|
|
use Orm\Zed\Sales\Persistence\SpySalesShipmentQuery; |
|
27
|
|
|
use Orm\Zed\Shipment\Persistence\SpyShipmentMethod; |
|
28
|
|
|
use Orm\Zed\Shipment\Persistence\SpyShipmentMethodPriceQuery; |
|
29
|
|
|
use Orm\Zed\Shipment\Persistence\SpyShipmentMethodQuery; |
|
30
|
|
|
use Orm\Zed\Tax\Persistence\Map\SpyTaxRateTableMap; |
|
31
|
|
|
use Orm\Zed\Tax\Persistence\Map\SpyTaxSetTableMap; |
|
32
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
|
33
|
|
|
use Propel\Runtime\ActiveQuery\ModelCriteria; |
|
34
|
|
|
use Propel\Runtime\Collection\Collection; |
|
35
|
|
|
use Spryker\Shared\Tax\TaxConstants; |
|
36
|
|
|
use Spryker\Zed\Kernel\Persistence\AbstractRepository; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @method \Spryker\Zed\Shipment\Persistence\ShipmentPersistenceFactory getFactory() |
|
40
|
|
|
*/ |
|
41
|
|
|
class ShipmentRepository extends AbstractRepository implements ShipmentRepositoryInterface |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected const COL_MAX_TAX_RATE = 'maxTaxRate'; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param \Generated\Shared\Transfer\ShipmentMethodTransfer $methodTransfer |
|
50
|
|
|
* @param string $countryIso2Code |
|
51
|
|
|
* |
|
52
|
|
|
* @return \Generated\Shared\Transfer\TaxSetTransfer|null |
|
53
|
|
|
*/ |
|
54
|
|
|
public function findTaxSetByShipmentMethodAndCountryIso2Code( |
|
55
|
|
|
ShipmentMethodTransfer $methodTransfer, |
|
56
|
|
|
string $countryIso2Code |
|
57
|
|
|
): ?TaxSetTransfer { |
|
58
|
|
|
/** @var \Orm\Zed\Shipment\Persistence\SpyShipmentMethod|null $shipmentMethodEntity */ |
|
59
|
|
|
$shipmentMethodEntity = $this->getFactory() |
|
60
|
|
|
->createShipmentMethodQuery() |
|
61
|
|
|
->filterByIdShipmentMethod($methodTransfer->getIdShipmentMethod()) |
|
62
|
|
|
->leftJoinWithTaxSet() |
|
63
|
|
|
->useTaxSetQuery() |
|
64
|
|
|
->useSpyTaxSetTaxQuery() |
|
65
|
|
|
->useSpyTaxRateQuery() |
|
66
|
|
|
->useCountryQuery() |
|
67
|
|
|
->filterByIso2Code($countryIso2Code) |
|
68
|
|
|
->endUse() |
|
69
|
|
|
->_or() |
|
70
|
|
|
->filterByName(TaxConstants::TAX_EXEMPT_PLACEHOLDER) |
|
71
|
|
|
->endUse() |
|
72
|
|
|
->endUse() |
|
73
|
|
|
->groupBy(SpyTaxSetTableMap::COL_NAME) |
|
74
|
|
|
->withColumn('MAX(' . SpyTaxRateTableMap::COL_RATE . ')', static::COL_MAX_TAX_RATE) |
|
75
|
|
|
->endUse() |
|
76
|
|
|
->findOne(); |
|
77
|
|
|
|
|
78
|
|
|
if ($shipmentMethodEntity === null || $shipmentMethodEntity->getTaxSet() === null) { |
|
79
|
|
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$taxSetTransfer = $this->getFactory() |
|
83
|
|
|
->createTaxSetMapper() |
|
84
|
|
|
->mapTaxSetEntityToTaxSetTransfer( |
|
85
|
|
|
$shipmentMethodEntity->getTaxSet(), |
|
86
|
|
|
new TaxSetTransfer(), |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
return $taxSetTransfer->setEffectiveRate($shipmentMethodEntity->getVirtualColumn(static::COL_MAX_TAX_RATE)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
|
94
|
|
|
* |
|
95
|
|
|
* @return array<\Generated\Shared\Transfer\ShipmentTransfer> |
|
96
|
|
|
*/ |
|
97
|
|
|
public function findShipmentTransfersByOrder(OrderTransfer $orderTransfer): array |
|
98
|
|
|
{ |
|
99
|
|
|
$salesOrderShipments = $this->getFactory() |
|
100
|
|
|
->createSalesShipmentQuery() |
|
101
|
|
|
->leftJoinWithSpySalesOrderAddress() |
|
102
|
|
|
->filterByFkSalesOrder($orderTransfer->getIdSalesOrder()) |
|
103
|
|
|
->find(); |
|
104
|
|
|
|
|
105
|
|
|
if ($salesOrderShipments->count() === 0) { |
|
106
|
|
|
return []; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $this->getFactory() |
|
110
|
|
|
->createShipmentMapper() |
|
111
|
|
|
->mapShipmentEntitiesToShipmentTransfers($salesOrderShipments, []); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
|
116
|
|
|
* @param \Generated\Shared\Transfer\ShipmentTransfer|null $defaultShipmentTransfer |
|
117
|
|
|
* |
|
118
|
|
|
* @return array<array<int>> |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getItemIdsGroupedByShipmentIds( |
|
121
|
|
|
OrderTransfer $orderTransfer, |
|
122
|
|
|
?ShipmentTransfer $defaultShipmentTransfer = null |
|
123
|
|
|
): array { |
|
124
|
|
|
$salesOrderItemIdsWithShipmentIds = $this->getFactory() |
|
125
|
|
|
->createSalesOrderItemQuery() |
|
126
|
|
|
->filterByFkSalesOrder($orderTransfer->getIdSalesOrder()) |
|
127
|
|
|
->select([SpySalesOrderItemTableMap::COL_FK_SALES_SHIPMENT, SpySalesOrderItemTableMap::COL_ID_SALES_ORDER_ITEM]) |
|
128
|
|
|
->find(); |
|
129
|
|
|
|
|
130
|
|
|
if ($salesOrderItemIdsWithShipmentIds->count() === 0) { |
|
131
|
|
|
return []; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return $this->groupSalesOrderItemIdsByShipmentId($salesOrderItemIdsWithShipmentIds, $defaultShipmentTransfer); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param array<\Generated\Shared\Transfer\ShipmentTransfer> $shipmentTransfers |
|
139
|
|
|
* |
|
140
|
|
|
* @return array<\Generated\Shared\Transfer\ShipmentMethodTransfer> |
|
141
|
|
|
*/ |
|
142
|
|
|
public function findShipmentMethodTransfersByShipment(array $shipmentTransfers): array |
|
143
|
|
|
{ |
|
144
|
|
|
if (count($shipmentTransfers) === 0) { |
|
145
|
|
|
return []; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$shipmentMethodNames = $this->getShipmentMethodNames($shipmentTransfers); |
|
149
|
|
|
|
|
150
|
|
|
$salesShipmentMethods = $this->getFactory() |
|
151
|
|
|
->createShipmentMethodQuery() |
|
152
|
|
|
->filterByIsActive(true) |
|
153
|
|
|
->filterByName_In($shipmentMethodNames) |
|
154
|
|
|
->find(); |
|
155
|
|
|
|
|
156
|
|
|
if ($salesShipmentMethods->count() === 0) { |
|
157
|
|
|
return []; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return $this->getFactory() |
|
161
|
|
|
->createShipmentMethodMapper() |
|
162
|
|
|
->mapShipmentMethodEntitiesToShipmentMethodTransfers($salesShipmentMethods, []); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param string $shipmentMethodName |
|
167
|
|
|
* |
|
168
|
|
|
* @return \Generated\Shared\Transfer\ShipmentMethodTransfer|null |
|
169
|
|
|
*/ |
|
170
|
|
|
public function findShipmentMethodByName(string $shipmentMethodName): ?ShipmentMethodTransfer |
|
171
|
|
|
{ |
|
172
|
|
|
$salesShipmentMethodEntity = $this->queryMethodsWithMethodPricesAndCarrier() |
|
173
|
|
|
->filterByName($shipmentMethodName) |
|
174
|
|
|
->find() |
|
175
|
|
|
->getFirst(); |
|
176
|
|
|
|
|
177
|
|
|
if ($salesShipmentMethodEntity === null) { |
|
178
|
|
|
return null; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
return $this->getFactory() |
|
182
|
|
|
->createShipmentMethodMapper() |
|
183
|
|
|
->mapShipmentMethodEntityToShipmentMethodTransferWithPrices( |
|
184
|
|
|
$salesShipmentMethodEntity, |
|
185
|
|
|
new ShipmentMethodTransfer(), |
|
186
|
|
|
); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @param string $shipmentMethodKey |
|
191
|
|
|
* |
|
192
|
|
|
* @return \Generated\Shared\Transfer\ShipmentMethodTransfer|null |
|
193
|
|
|
*/ |
|
194
|
|
|
public function findShipmentMethodByKey(string $shipmentMethodKey): ?ShipmentMethodTransfer |
|
195
|
|
|
{ |
|
196
|
|
|
$shipmentMethodEntity = $this->queryMethodsWithMethodPricesAndCarrier() |
|
197
|
|
|
->filterByShipmentMethodKey($shipmentMethodKey) |
|
198
|
|
|
->find() |
|
199
|
|
|
->getFirst(); |
|
200
|
|
|
|
|
201
|
|
|
if ($shipmentMethodEntity === null) { |
|
202
|
|
|
return null; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
return $this->getFactory() |
|
206
|
|
|
->createShipmentMethodMapper() |
|
207
|
|
|
->mapShipmentMethodEntityToShipmentMethodTransferWithPrices( |
|
208
|
|
|
$shipmentMethodEntity, |
|
209
|
|
|
new ShipmentMethodTransfer(), |
|
210
|
|
|
); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @param int $idShipmentMethod |
|
215
|
|
|
* @param int $idStore |
|
216
|
|
|
* |
|
217
|
|
|
* @return \Generated\Shared\Transfer\ShipmentMethodTransfer|null |
|
218
|
|
|
*/ |
|
219
|
|
|
public function findShipmentMethodByIdAndIdStore(int $idShipmentMethod, int $idStore): ?ShipmentMethodTransfer |
|
220
|
|
|
{ |
|
221
|
|
|
/** @var \Orm\Zed\Shipment\Persistence\SpyShipmentMethod|null $salesShipmentMethodEntity */ |
|
222
|
|
|
$salesShipmentMethodEntity = $this->queryMethods() |
|
223
|
|
|
->useShipmentMethodStoreQuery() |
|
224
|
|
|
->filterByFkStore($idStore) |
|
225
|
|
|
->endUse() |
|
226
|
|
|
->filterByIdShipmentMethod($idShipmentMethod) |
|
227
|
|
|
->filterByPricePlugin(null, Criteria::ISNOTNULL) |
|
228
|
|
|
->_or() |
|
229
|
|
|
->useShipmentMethodPriceQuery(null, Criteria::LEFT_JOIN) |
|
230
|
|
|
->filterByFkStore($idStore) |
|
231
|
|
|
->endUse() |
|
232
|
|
|
->findOne(); |
|
233
|
|
|
|
|
234
|
|
|
if ($salesShipmentMethodEntity === null) { |
|
235
|
|
|
return null; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
return $this->getFactory() |
|
239
|
|
|
->createShipmentMethodMapper() |
|
240
|
|
|
->mapShipmentMethodEntityToShipmentMethodTransferWithPrices( |
|
241
|
|
|
$salesShipmentMethodEntity, |
|
242
|
|
|
new ShipmentMethodTransfer(), |
|
243
|
|
|
); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @param int $idShipmentMethod |
|
248
|
|
|
* |
|
249
|
|
|
* @return \Generated\Shared\Transfer\ShipmentMethodTransfer|null |
|
250
|
|
|
*/ |
|
251
|
|
|
public function findShipmentMethodByIdWithPricesAndCarrier(int $idShipmentMethod): ?ShipmentMethodTransfer |
|
252
|
|
|
{ |
|
253
|
|
|
$salesShipmentMethodEntity = $this->queryMethodsWithMethodPricesAndCarrier() |
|
254
|
|
|
->filterByIdShipmentMethod($idShipmentMethod) |
|
255
|
|
|
->find() |
|
256
|
|
|
->getFirst(); |
|
257
|
|
|
|
|
258
|
|
|
if ($salesShipmentMethodEntity === null) { |
|
259
|
|
|
return null; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
return $this->getFactory() |
|
263
|
|
|
->createShipmentMethodMapper() |
|
264
|
|
|
->mapShipmentMethodEntityToShipmentMethodTransferWithPrices( |
|
265
|
|
|
$salesShipmentMethodEntity, |
|
266
|
|
|
new ShipmentMethodTransfer(), |
|
267
|
|
|
); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @deprecated Use {@link \Spryker\Zed\Shipment\Persistence\ShipmentRepository::getSalesShipmentCollection()} instead. |
|
272
|
|
|
* |
|
273
|
|
|
* @param int $idShipmentMethod |
|
274
|
|
|
* |
|
275
|
|
|
* @return \Generated\Shared\Transfer\ShipmentTransfer|null |
|
276
|
|
|
*/ |
|
277
|
|
|
public function findShipmentById(int $idShipmentMethod): ?ShipmentTransfer |
|
278
|
|
|
{ |
|
279
|
|
|
/** @var \Orm\Zed\Sales\Persistence\SpySalesShipment|null $salesShipmentEntity */ |
|
280
|
|
|
$salesShipmentEntity = $this->getFactory() |
|
281
|
|
|
->createSalesShipmentQuery() |
|
282
|
|
|
->filterByIdSalesShipment($idShipmentMethod) |
|
283
|
|
|
->leftJoinWithSpySalesOrderAddress() |
|
284
|
|
|
->useSpySalesOrderAddressQuery() |
|
285
|
|
|
->leftJoinCountry() |
|
286
|
|
|
->endUse() |
|
287
|
|
|
->findOne(); |
|
288
|
|
|
|
|
289
|
|
|
if ($salesShipmentEntity === null) { |
|
290
|
|
|
return null; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
return $this->getFactory() |
|
294
|
|
|
->createShipmentMapper() |
|
295
|
|
|
->mapShipmentEntityToShipmentTransferWithDetails($salesShipmentEntity, new ShipmentTransfer()); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @return array<\Generated\Shared\Transfer\ShipmentMethodTransfer> |
|
300
|
|
|
*/ |
|
301
|
|
|
public function getActiveShipmentMethods(): array |
|
302
|
|
|
{ |
|
303
|
|
|
$shipmentMethodList = []; |
|
304
|
|
|
$shipmentMethodEntities = $this->queryActiveMethodsWithMethodPricesAndCarrier()->find(); |
|
305
|
|
|
|
|
306
|
|
|
if ($shipmentMethodEntities->count() === 0) { |
|
307
|
|
|
return $shipmentMethodList; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
foreach ($shipmentMethodEntities as $shipmentMethodEntity) { |
|
311
|
|
|
$shipmentMethodTransfer = $this->getFactory() |
|
312
|
|
|
->createShipmentMethodMapper() |
|
313
|
|
|
->mapShipmentMethodEntityToShipmentMethodTransferWithPrices( |
|
314
|
|
|
$shipmentMethodEntity, |
|
315
|
|
|
new ShipmentMethodTransfer(), |
|
316
|
|
|
); |
|
317
|
|
|
|
|
318
|
|
|
$shipmentMethodList[] = $shipmentMethodTransfer; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
return $shipmentMethodList; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @param int $idStore |
|
326
|
|
|
* |
|
327
|
|
|
* @return array<\Generated\Shared\Transfer\ShipmentMethodTransfer> |
|
328
|
|
|
*/ |
|
329
|
|
|
public function getActiveShipmentMethodsForStore(int $idStore): array |
|
330
|
|
|
{ |
|
331
|
|
|
$shipmentMethodList = []; |
|
332
|
|
|
$shipmentMethodEntities = $this->getActiveMethodsWithMethodPricesAndCarrierForStore($idStore); |
|
333
|
|
|
|
|
334
|
|
|
if ($shipmentMethodEntities->count() === 0) { |
|
335
|
|
|
return $shipmentMethodList; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
foreach ($shipmentMethodEntities as $shipmentMethodEntity) { |
|
339
|
|
|
$shipmentMethodTransfer = $this->getFactory() |
|
340
|
|
|
->createShipmentMethodMapper() |
|
341
|
|
|
->mapShipmentMethodEntityToShipmentMethodTransferWithPrices( |
|
342
|
|
|
$shipmentMethodEntity, |
|
343
|
|
|
new ShipmentMethodTransfer(), |
|
344
|
|
|
); |
|
345
|
|
|
|
|
346
|
|
|
$shipmentMethodList[] = $shipmentMethodTransfer; |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
return $shipmentMethodList; |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* @param int $idShipmentMethod |
|
354
|
|
|
* @param int $idStore |
|
355
|
|
|
* @param int $idCurrency |
|
356
|
|
|
* |
|
357
|
|
|
* @return \Generated\Shared\Transfer\ShipmentPriceTransfer|null |
|
358
|
|
|
*/ |
|
359
|
|
|
public function findShipmentMethodPrice(int $idShipmentMethod, int $idStore, int $idCurrency): ?ShipmentPriceTransfer |
|
360
|
|
|
{ |
|
361
|
|
|
$shipmentMethodPriceEntity = $this->queryMethodPriceByShipmentMethodAndStoreCurrency( |
|
362
|
|
|
$idShipmentMethod, |
|
363
|
|
|
$idStore, |
|
364
|
|
|
$idCurrency, |
|
365
|
|
|
)->findOne(); |
|
366
|
|
|
|
|
367
|
|
|
if ($shipmentMethodPriceEntity === null) { |
|
368
|
|
|
return null; |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
return $this->getFactory() |
|
372
|
|
|
->createShipmentMethodMapper() |
|
373
|
|
|
->mapShipmentMethodPriceEntityToShipmentPriceTransfer( |
|
374
|
|
|
$shipmentMethodPriceEntity, |
|
375
|
|
|
new ShipmentPriceTransfer(), |
|
376
|
|
|
); |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* @param int $idShipmentMethod |
|
381
|
|
|
* |
|
382
|
|
|
* @return bool |
|
383
|
|
|
*/ |
|
384
|
|
|
public function hasShipmentMethodByIdShipmentMethod(int $idShipmentMethod): bool |
|
385
|
|
|
{ |
|
386
|
|
|
return $this->getFactory() |
|
387
|
|
|
->createShipmentMethodQuery() |
|
388
|
|
|
->filterByIdShipmentMethod($idShipmentMethod) |
|
389
|
|
|
->exists(); |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* @param int $idShipmentMethod |
|
394
|
|
|
* |
|
395
|
|
|
* @return bool |
|
396
|
|
|
*/ |
|
397
|
|
|
public function hasActiveShipmentMethodByIdShipmentMethod(int $idShipmentMethod): bool |
|
398
|
|
|
{ |
|
399
|
|
|
return $this->getFactory() |
|
400
|
|
|
->createShipmentMethodQuery() |
|
401
|
|
|
->filterByIdShipmentMethod($idShipmentMethod) |
|
402
|
|
|
->filterByIsActive(true) |
|
403
|
|
|
->exists(); |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
|
|
/** |
|
407
|
|
|
* @param int $idSalesOrder |
|
408
|
|
|
* |
|
409
|
|
|
* @return \Generated\Shared\Transfer\OrderTransfer|null |
|
410
|
|
|
*/ |
|
411
|
|
|
public function findSalesOrderById(int $idSalesOrder): ?OrderTransfer |
|
412
|
|
|
{ |
|
413
|
|
|
$salesOrderEntity = $this->getFactory() |
|
414
|
|
|
->createSalesOrderQuery() |
|
415
|
|
|
->filterByIdSalesOrder($idSalesOrder) |
|
416
|
|
|
->findOne(); |
|
417
|
|
|
|
|
418
|
|
|
if ($salesOrderEntity === null) { |
|
419
|
|
|
return null; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
return $this->getFactory() |
|
423
|
|
|
->createShipmentOrderMapper() |
|
424
|
|
|
->mapSalesOrderEntityToOrderTransfer($salesOrderEntity, new OrderTransfer()); |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/** |
|
428
|
|
|
* @param \Generated\Shared\Transfer\ShipmentCarrierRequestTransfer $shipmentCarrierRequestTransfer |
|
429
|
|
|
* |
|
430
|
|
|
* @return \Generated\Shared\Transfer\ShipmentCarrierTransfer|null |
|
431
|
|
|
*/ |
|
432
|
|
|
public function findShipmentCarrier(ShipmentCarrierRequestTransfer $shipmentCarrierRequestTransfer): ?ShipmentCarrierTransfer |
|
433
|
|
|
{ |
|
434
|
|
|
$shipmentCarrierQuery = $this->getFactory()->createShipmentCarrierQuery(); |
|
435
|
|
|
|
|
436
|
|
|
if ($shipmentCarrierRequestTransfer->getIdCarrier() === null) { |
|
437
|
|
|
$shipmentCarrierRequestTransfer->requireCarrierName(); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
if ($shipmentCarrierRequestTransfer->getCarrierName() === null) { |
|
441
|
|
|
$shipmentCarrierRequestTransfer->requireIdCarrier(); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
if ($shipmentCarrierRequestTransfer->getIdCarrier() !== null) { |
|
445
|
|
|
$shipmentCarrierQuery->filterByIdShipmentCarrier($shipmentCarrierRequestTransfer->getIdCarrier()); |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
if ($shipmentCarrierRequestTransfer->getCarrierName() !== null) { |
|
449
|
|
|
$shipmentCarrierQuery->filterByName($shipmentCarrierRequestTransfer->getCarrierName()); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
if ($shipmentCarrierRequestTransfer->getExcludedCarrierIds() !== []) { |
|
453
|
|
|
$shipmentCarrierQuery->filterByIdShipmentCarrier($shipmentCarrierRequestTransfer->getExcludedCarrierIds(), Criteria::NOT_IN); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
$shipmentCarrierEntity = $shipmentCarrierQuery->findOne(); |
|
457
|
|
|
if ($shipmentCarrierEntity === null) { |
|
458
|
|
|
return null; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
return $this->getFactory() |
|
462
|
|
|
->createShipmentCarrierMapper() |
|
463
|
|
|
->mapShipmentCarrierEntityToShipmentCarrierTransfer($shipmentCarrierEntity, new ShipmentCarrierTransfer()); |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* @param iterable<\Generated\Shared\Transfer\ShipmentTransfer> $shipmentTransfers |
|
468
|
|
|
* |
|
469
|
|
|
* @return array<string> |
|
470
|
|
|
*/ |
|
471
|
|
|
protected function getShipmentMethodNames(iterable $shipmentTransfers): array |
|
472
|
|
|
{ |
|
473
|
|
|
$shipmentMethodNames = []; |
|
474
|
|
|
foreach ($shipmentTransfers as $shipmentTransfer) { |
|
475
|
|
|
$shipmentMethodTransfer = $shipmentTransfer->getMethod(); |
|
476
|
|
|
if ($shipmentMethodTransfer === null) { |
|
477
|
|
|
continue; |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
$shipmentMethodName = $shipmentMethodTransfer->getName(); |
|
481
|
|
|
if ($shipmentMethodName === '') { |
|
482
|
|
|
continue; |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
$shipmentMethodNames[$shipmentMethodName] = $shipmentMethodName; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
return $shipmentMethodNames; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* @param iterable<\Generated\Shared\Transfer\ShipmentMethodTransfer> $shipmentMethodTransfers |
|
493
|
|
|
* @param \Generated\Shared\Transfer\ShipmentTransfer $shipmentTransfer |
|
494
|
|
|
* |
|
495
|
|
|
* @return \Generated\Shared\Transfer\ShipmentMethodTransfer|null |
|
496
|
|
|
*/ |
|
497
|
|
|
protected function findShipmentMethodTransferByName(iterable $shipmentMethodTransfers, ShipmentTransfer $shipmentTransfer): ?ShipmentMethodTransfer |
|
498
|
|
|
{ |
|
499
|
|
|
foreach ($shipmentMethodTransfers as $shipmentMethodTransfer) { |
|
500
|
|
|
if ($shipmentTransfer->getMethod()->getName() === $shipmentMethodTransfer->getName()) { |
|
501
|
|
|
return clone $shipmentMethodTransfer; |
|
502
|
|
|
} |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
return null; |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
/** |
|
509
|
|
|
* @param iterable|array $salesOrderItemIdsWithShipmentIds |
|
510
|
|
|
* @param \Generated\Shared\Transfer\ShipmentTransfer|null $defaultShipmentTransfer |
|
511
|
|
|
* |
|
512
|
|
|
* @return array<array<int>> |
|
513
|
|
|
*/ |
|
514
|
|
|
protected function groupSalesOrderItemIdsByShipmentId( |
|
515
|
|
|
iterable $salesOrderItemIdsWithShipmentIds, |
|
516
|
|
|
?ShipmentTransfer $defaultShipmentTransfer = null |
|
517
|
|
|
): array { |
|
518
|
|
|
$groupedResult = []; |
|
519
|
|
|
$idDefaultShipmentTransfer = null; |
|
520
|
|
|
|
|
521
|
|
|
if ($defaultShipmentTransfer !== null) { |
|
522
|
|
|
$idDefaultShipmentTransfer = $defaultShipmentTransfer->getIdSalesShipment(); |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
foreach ( |
|
526
|
|
|
$salesOrderItemIdsWithShipmentIds as [ |
|
527
|
|
|
SpySalesOrderItemTableMap::COL_FK_SALES_SHIPMENT => $shipmentId, |
|
528
|
|
|
SpySalesOrderItemTableMap::COL_ID_SALES_ORDER_ITEM => $orderItemId, |
|
529
|
|
|
] |
|
530
|
|
|
) { |
|
531
|
|
|
$shipmentId = $shipmentId ?? $idDefaultShipmentTransfer; |
|
532
|
|
|
if (!isset($groupedResult[$shipmentId])) { |
|
533
|
|
|
$groupedResult[$shipmentId] = []; |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
$groupedResult[$shipmentId][] = $orderItemId; |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
return $groupedResult; |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
/** |
|
543
|
|
|
* @module Currency |
|
544
|
|
|
* |
|
545
|
|
|
* @return \Orm\Zed\Shipment\Persistence\SpyShipmentMethodQuery |
|
546
|
|
|
*/ |
|
547
|
|
|
protected function queryMethodsWithMethodPricesAndCarrier(): SpyShipmentMethodQuery |
|
548
|
|
|
{ |
|
549
|
|
|
/** @phpstan-var \Orm\Zed\Shipment\Persistence\SpyShipmentMethodQuery */ |
|
550
|
|
|
return $this->queryMethods() |
|
551
|
|
|
->leftJoinWithShipmentCarrier() |
|
552
|
|
|
->joinWithShipmentMethodPrice() |
|
553
|
|
|
->useShipmentMethodPriceQuery() |
|
554
|
|
|
->joinWithCurrency() |
|
555
|
|
|
->joinWithStore() |
|
556
|
|
|
->endUse(); |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
/** |
|
560
|
|
|
* @return \Orm\Zed\Shipment\Persistence\SpyShipmentMethodQuery |
|
561
|
|
|
*/ |
|
562
|
|
|
protected function queryMethods(): SpyShipmentMethodQuery |
|
563
|
|
|
{ |
|
564
|
|
|
return $this->getFactory()->createShipmentMethodQuery(); |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
/** |
|
568
|
|
|
* @return \Orm\Zed\Shipment\Persistence\SpyShipmentMethodQuery |
|
569
|
|
|
*/ |
|
570
|
|
|
protected function queryActiveMethodsWithMethodPricesAndCarrier(): SpyShipmentMethodQuery |
|
571
|
|
|
{ |
|
572
|
|
|
return $this->queryMethodsWithMethodPricesAndCarrier() |
|
573
|
|
|
->filterByIsActive(true); |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
/** |
|
577
|
|
|
* @param int $idStore |
|
578
|
|
|
* |
|
579
|
|
|
* @return \Propel\Runtime\Collection\Collection<\Orm\Zed\Shipment\Persistence\SpyShipmentMethod> |
|
580
|
|
|
*/ |
|
581
|
|
|
protected function getActiveMethodsWithMethodPricesAndCarrierForStore(int $idStore): Collection |
|
582
|
|
|
{ |
|
583
|
|
|
$shipmentMethodEntities = $this->queryMethods() |
|
584
|
|
|
->filterByIsActive(true) |
|
585
|
|
|
->groupByIdShipmentMethod() |
|
586
|
|
|
->leftJoinWithShipmentCarrier() |
|
587
|
|
|
->useShipmentMethodStoreQuery() |
|
588
|
|
|
->filterByFkStore($idStore) |
|
589
|
|
|
->endUse() |
|
590
|
|
|
->filterByPricePlugin(null, Criteria::ISNOTNULL) |
|
591
|
|
|
->_or() |
|
592
|
|
|
->useShipmentMethodPriceQuery(null, Criteria::LEFT_JOIN) |
|
593
|
|
|
->filterByFkStore($idStore) |
|
594
|
|
|
->endUse() |
|
595
|
|
|
->find(); |
|
596
|
|
|
|
|
597
|
|
|
if ($shipmentMethodEntities->count() === 0) { |
|
598
|
|
|
return $shipmentMethodEntities; |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
return $this->expandShipmentMethodEntitiesWithShipmentMethodPricesForStore($shipmentMethodEntities, $idStore); |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
/** |
|
605
|
|
|
* @param int $idShipmentMethod |
|
606
|
|
|
* @param int $idStore |
|
607
|
|
|
* @param int $idCurrency |
|
608
|
|
|
* |
|
609
|
|
|
* @return \Orm\Zed\Shipment\Persistence\SpyShipmentMethodPriceQuery |
|
610
|
|
|
*/ |
|
611
|
|
|
protected function queryMethodPriceByShipmentMethodAndStoreCurrency( |
|
612
|
|
|
int $idShipmentMethod, |
|
613
|
|
|
int $idStore, |
|
614
|
|
|
int $idCurrency |
|
615
|
|
|
): SpyShipmentMethodPriceQuery { |
|
616
|
|
|
return $this->queryMethodPrices() |
|
617
|
|
|
->filterByFkShipmentMethod($idShipmentMethod) |
|
618
|
|
|
->filterByFkStore($idStore) |
|
619
|
|
|
->filterByFkCurrency($idCurrency); |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
/** |
|
623
|
|
|
* @return \Orm\Zed\Shipment\Persistence\SpyShipmentMethodPriceQuery |
|
624
|
|
|
*/ |
|
625
|
|
|
protected function queryMethodPrices(): SpyShipmentMethodPriceQuery |
|
626
|
|
|
{ |
|
627
|
|
|
return $this->getFactory()->createShipmentMethodPriceQuery(); |
|
628
|
|
|
} |
|
629
|
|
|
|
|
630
|
|
|
/** |
|
631
|
|
|
* @param int $idSalesOrder |
|
632
|
|
|
* @param int $idSalesShipment |
|
633
|
|
|
* |
|
634
|
|
|
* @return \ArrayObject<int, \Generated\Shared\Transfer\ItemTransfer> |
|
635
|
|
|
*/ |
|
636
|
|
|
public function findSalesOrderItemsBySalesShipmentId(int $idSalesOrder, int $idSalesShipment): ArrayObject |
|
637
|
|
|
{ |
|
638
|
|
|
$salesOrderItemEntities = $this->getFactory() |
|
639
|
|
|
->createSalesOrderItemQuery() |
|
640
|
|
|
->filterByFkSalesOrder($idSalesOrder) |
|
641
|
|
|
->filterByFkSalesShipment($idSalesShipment) |
|
642
|
|
|
->_or() |
|
643
|
|
|
->filterByFkSalesShipment(null) |
|
644
|
|
|
->find(); |
|
645
|
|
|
|
|
646
|
|
|
if ($salesOrderItemEntities->count() === 0) { |
|
647
|
|
|
return new ArrayObject(); |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
$salesOrderItemMapper = $this->getFactory()->createShipmentSalesOrderItemMapper(); |
|
651
|
|
|
|
|
652
|
|
|
$itemTransfers = new ArrayObject(); |
|
653
|
|
|
foreach ($salesOrderItemEntities as $salesOrderItemEntity) { |
|
654
|
|
|
$itemTransfer = $salesOrderItemMapper |
|
655
|
|
|
->mapSalesOrderItemEntityToItemTransfer($salesOrderItemEntity, new ItemTransfer()); |
|
656
|
|
|
|
|
657
|
|
|
$itemTransfers->append($itemTransfer); |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
return $itemTransfers; |
|
661
|
|
|
} |
|
662
|
|
|
|
|
663
|
|
|
/** |
|
664
|
|
|
* @param \Generated\Shared\Transfer\ShipmentMethodTransfer $shipmentMethodTransfer |
|
665
|
|
|
* |
|
666
|
|
|
* @return bool |
|
667
|
|
|
*/ |
|
668
|
|
|
public function isShipmentMethodUniqueForCarrier(ShipmentMethodTransfer $shipmentMethodTransfer): bool |
|
669
|
|
|
{ |
|
670
|
|
|
$shipmentMethodTransfer->requireName() |
|
671
|
|
|
->requireFkShipmentCarrier(); |
|
672
|
|
|
|
|
673
|
|
|
return !$this->getFactory() |
|
674
|
|
|
->createShipmentMethodQuery() |
|
675
|
|
|
->filterByName($shipmentMethodTransfer->getName()) |
|
676
|
|
|
->filterByIdShipmentMethod($shipmentMethodTransfer->getIdShipmentMethod(), Criteria::NOT_EQUAL) |
|
677
|
|
|
->filterByFkShipmentCarrier($shipmentMethodTransfer->getFkShipmentCarrier()) |
|
678
|
|
|
->exists(); |
|
679
|
|
|
} |
|
680
|
|
|
|
|
681
|
|
|
/** |
|
682
|
|
|
* @param int $idShipmentMethod |
|
683
|
|
|
* |
|
684
|
|
|
* @return \Generated\Shared\Transfer\StoreRelationTransfer |
|
685
|
|
|
*/ |
|
686
|
|
|
public function getStoreRelationByIdShipmentMethod(int $idShipmentMethod): StoreRelationTransfer |
|
687
|
|
|
{ |
|
688
|
|
|
$shipmentMethodStoreEntities = $this->getFactory() |
|
689
|
|
|
->createShipmentMethodStoreQuery() |
|
690
|
|
|
->filterByFkShipmentMethod($idShipmentMethod) |
|
691
|
|
|
->leftJoinWithStore() |
|
692
|
|
|
->find(); |
|
693
|
|
|
|
|
694
|
|
|
$storeRelationTransfer = (new StoreRelationTransfer())->setIdEntity($idShipmentMethod); |
|
695
|
|
|
|
|
696
|
|
|
return $this->getFactory() |
|
697
|
|
|
->createStoreRelationMapper() |
|
698
|
|
|
->mapShipmentMethodStoreEntitiesToStoreRelationTransfer($shipmentMethodStoreEntities, $storeRelationTransfer); |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
/** |
|
702
|
|
|
* @return array<\Generated\Shared\Transfer\ShipmentCarrierTransfer> |
|
703
|
|
|
*/ |
|
704
|
|
|
public function getActiveShipmentCarriers(): array |
|
705
|
|
|
{ |
|
706
|
|
|
$shipmentCarrierEntityCollection = $this->getFactory() |
|
707
|
|
|
->createShipmentCarrierQuery() |
|
708
|
|
|
->filterByIsActive(true) |
|
709
|
|
|
->find(); |
|
710
|
|
|
|
|
711
|
|
|
return $this->getFactory() |
|
712
|
|
|
->createShipmentCarrierMapper() |
|
713
|
|
|
->mapShipmentCarrierEntityCollectionToShipmentCarrierTransferCollection($shipmentCarrierEntityCollection, []); |
|
714
|
|
|
} |
|
715
|
|
|
|
|
716
|
|
|
/** |
|
717
|
|
|
* @param \Generated\Shared\Transfer\SalesShipmentCriteriaTransfer $salesShipmentCriteriaTransfer |
|
718
|
|
|
* |
|
719
|
|
|
* @return \Generated\Shared\Transfer\SalesShipmentCollectionTransfer |
|
720
|
|
|
*/ |
|
721
|
|
|
public function getSalesShipmentCollection( |
|
722
|
|
|
SalesShipmentCriteriaTransfer $salesShipmentCriteriaTransfer |
|
723
|
|
|
): SalesShipmentCollectionTransfer { |
|
724
|
|
|
$salesShipmentQuery = $this->getFactory()->createSalesShipmentQuery(); |
|
725
|
|
|
|
|
726
|
|
|
if ($salesShipmentCriteriaTransfer->getSalesShipmentConditions() && $salesShipmentCriteriaTransfer->getSalesShipmentConditionsOrFail()->getWithOrderItems()) { |
|
727
|
|
|
$salesShipmentQuery->leftJoinWithSpySalesOrderItem(); |
|
728
|
|
|
} |
|
729
|
|
|
$salesShipmentQuery = $this->applySalesShipmentFilters($salesShipmentQuery, $salesShipmentCriteriaTransfer); |
|
730
|
|
|
$salesShipmentQuery = $this->applySortingToQuery($salesShipmentQuery, $salesShipmentCriteriaTransfer->getSortCollection()); |
|
731
|
|
|
|
|
732
|
|
|
$paginationTransfer = $salesShipmentCriteriaTransfer->getPagination(); |
|
733
|
|
|
$salesShipmentCollectionTransfer = new SalesShipmentCollectionTransfer(); |
|
734
|
|
|
|
|
735
|
|
|
if ($paginationTransfer !== null) { |
|
736
|
|
|
$salesShipmentQuery = $this->applyPaginationToQuery($salesShipmentQuery, $paginationTransfer); |
|
737
|
|
|
$salesShipmentCollectionTransfer->setPagination($paginationTransfer); |
|
738
|
|
|
} |
|
739
|
|
|
|
|
740
|
|
|
$salesShipmentEntities = $salesShipmentQuery->find(); |
|
741
|
|
|
if ($salesShipmentEntities->count() === 0) { |
|
742
|
|
|
return $salesShipmentCollectionTransfer; |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
return $this->getFactory() |
|
746
|
|
|
->createShipmentMapper() |
|
747
|
|
|
->mapSalesShipmentEntityCollectionToSalesShipmentCollectionTransfer( |
|
748
|
|
|
$salesShipmentEntities, |
|
749
|
|
|
$salesShipmentCollectionTransfer, |
|
750
|
|
|
$salesShipmentCriteriaTransfer->getSalesShipmentConditions(), |
|
751
|
|
|
); |
|
752
|
|
|
} |
|
753
|
|
|
|
|
754
|
|
|
/** |
|
755
|
|
|
* @param \Generated\Shared\Transfer\ShipmentMethodCriteriaTransfer $shipmentMethodCriteriaTransfer |
|
756
|
|
|
* |
|
757
|
|
|
* @return \Generated\Shared\Transfer\ShipmentMethodCollectionTransfer |
|
758
|
|
|
*/ |
|
759
|
|
|
public function getShipmentMethodCollection( |
|
760
|
|
|
ShipmentMethodCriteriaTransfer $shipmentMethodCriteriaTransfer |
|
761
|
|
|
): ShipmentMethodCollectionTransfer { |
|
762
|
|
|
$shipmentMethodQuery = $this->getFactory()->createShipmentMethodQuery(); |
|
763
|
|
|
|
|
764
|
|
|
$shipmentMethodQuery = $this->applyShipmentMethodFilters($shipmentMethodQuery, $shipmentMethodCriteriaTransfer); |
|
765
|
|
|
$shipmentMethodQuery = $this->applySortingToQuery($shipmentMethodQuery, $shipmentMethodCriteriaTransfer->getSortCollection()); |
|
766
|
|
|
|
|
767
|
|
|
$paginationTransfer = $shipmentMethodCriteriaTransfer->getPagination(); |
|
768
|
|
|
$shipmentMethodCollectionTransfer = new ShipmentMethodCollectionTransfer(); |
|
769
|
|
|
|
|
770
|
|
|
if ($paginationTransfer !== null) { |
|
771
|
|
|
$shipmentMethodQuery = $this->applyPaginationToQuery($shipmentMethodQuery, $paginationTransfer); |
|
772
|
|
|
$shipmentMethodCollectionTransfer->setPagination($paginationTransfer); |
|
773
|
|
|
} |
|
774
|
|
|
|
|
775
|
|
|
$shipmentMethodEntities = $shipmentMethodQuery->find(); |
|
776
|
|
|
if ($shipmentMethodEntities->count() === 0) { |
|
777
|
|
|
return $shipmentMethodCollectionTransfer; |
|
778
|
|
|
} |
|
779
|
|
|
|
|
780
|
|
|
return $this->getFactory() |
|
781
|
|
|
->createShipmentMethodMapper() |
|
782
|
|
|
->mapShipmentMethodEntitiesToShipmentMethodCollectionTransfer( |
|
783
|
|
|
$shipmentMethodEntities, |
|
784
|
|
|
$shipmentMethodCollectionTransfer, |
|
785
|
|
|
); |
|
786
|
|
|
} |
|
787
|
|
|
|
|
788
|
|
|
/** |
|
789
|
|
|
* @param \Propel\Runtime\Collection\Collection<\Orm\Zed\Shipment\Persistence\SpyShipmentMethod> $shipmentMethodEntities |
|
790
|
|
|
* @param int $idStore |
|
791
|
|
|
* |
|
792
|
|
|
* @return \Propel\Runtime\Collection\Collection<\Orm\Zed\Shipment\Persistence\SpyShipmentMethod> |
|
793
|
|
|
*/ |
|
794
|
|
|
protected function expandShipmentMethodEntitiesWithShipmentMethodPricesForStore( |
|
795
|
|
|
Collection $shipmentMethodEntities, |
|
796
|
|
|
int $idStore |
|
797
|
|
|
): Collection { |
|
798
|
|
|
$shipmentMethodWithoutPricePluginIds = $this->extractShipmentMethodWithoutPricePluginIds($shipmentMethodEntities); |
|
799
|
|
|
|
|
800
|
|
|
$shipmentMethodPriceEntities = $this->getFactory() |
|
801
|
|
|
->createShipmentMethodPriceQuery() |
|
802
|
|
|
->innerJoinWithCurrency() |
|
803
|
|
|
->filterByFkShipmentMethod_In($shipmentMethodWithoutPricePluginIds) |
|
804
|
|
|
->filterByFkStore($idStore) |
|
805
|
|
|
->find(); |
|
806
|
|
|
|
|
807
|
|
|
if ($shipmentMethodPriceEntities->count() === 0) { |
|
808
|
|
|
return $shipmentMethodEntities; |
|
809
|
|
|
} |
|
810
|
|
|
|
|
811
|
|
|
foreach ($shipmentMethodEntities as $shipmentMethodEntity) { |
|
812
|
|
|
$this->expandShipmentMethodEntityWithShipmentMethodPrices($shipmentMethodEntity, $shipmentMethodPriceEntities); |
|
813
|
|
|
} |
|
814
|
|
|
|
|
815
|
|
|
return $shipmentMethodEntities; |
|
816
|
|
|
} |
|
817
|
|
|
|
|
818
|
|
|
/** |
|
819
|
|
|
* @param \Propel\Runtime\Collection\Collection $shipmentMethodEntities |
|
820
|
|
|
* |
|
821
|
|
|
* @return array<int> |
|
822
|
|
|
*/ |
|
823
|
|
|
protected function extractShipmentMethodWithoutPricePluginIds(Collection $shipmentMethodEntities): array |
|
824
|
|
|
{ |
|
825
|
|
|
$idShipmentMethodsWithoutPricePlugins = []; |
|
826
|
|
|
foreach ($shipmentMethodEntities as $shipmentMethodEntity) { |
|
827
|
|
|
if ($shipmentMethodEntity->getPricePlugin()) { |
|
828
|
|
|
continue; |
|
829
|
|
|
} |
|
830
|
|
|
$idShipmentMethodsWithoutPricePlugins[] = $shipmentMethodEntity->getIdShipmentMethod(); |
|
831
|
|
|
} |
|
832
|
|
|
|
|
833
|
|
|
return $idShipmentMethodsWithoutPricePlugins; |
|
834
|
|
|
} |
|
835
|
|
|
|
|
836
|
|
|
/** |
|
837
|
|
|
* @param \Orm\Zed\Shipment\Persistence\SpyShipmentMethod $shipmentMethodEntity |
|
838
|
|
|
* @param \Propel\Runtime\Collection\Collection<\Orm\Zed\Shipment\Persistence\SpyShipmentMethodPrice> $shipmentMethodPriceEntities |
|
839
|
|
|
* |
|
840
|
|
|
* @return \Orm\Zed\Shipment\Persistence\SpyShipmentMethod |
|
841
|
|
|
*/ |
|
842
|
|
|
protected function expandShipmentMethodEntityWithShipmentMethodPrices( |
|
843
|
|
|
SpyShipmentMethod $shipmentMethodEntity, |
|
844
|
|
|
Collection $shipmentMethodPriceEntities |
|
845
|
|
|
): SpyShipmentMethod { |
|
846
|
|
|
foreach ($shipmentMethodPriceEntities as $shipmentMethodPriceEntity) { |
|
847
|
|
|
if ($shipmentMethodEntity->getIdShipmentMethod() === $shipmentMethodPriceEntity->getFkShipmentMethod()) { |
|
848
|
|
|
$shipmentMethodEntity->addShipmentMethodPrice($shipmentMethodPriceEntity); |
|
849
|
|
|
} |
|
850
|
|
|
} |
|
851
|
|
|
|
|
852
|
|
|
return $shipmentMethodEntity; |
|
853
|
|
|
} |
|
854
|
|
|
|
|
855
|
|
|
/** |
|
856
|
|
|
* @module Sales |
|
857
|
|
|
* |
|
858
|
|
|
* @param \Orm\Zed\Sales\Persistence\SpySalesShipmentQuery $salesShipmentQuery |
|
859
|
|
|
* @param \Generated\Shared\Transfer\SalesShipmentCriteriaTransfer $salesShipmentCriteriaTransfer |
|
860
|
|
|
* |
|
861
|
|
|
* @return \Orm\Zed\Sales\Persistence\SpySalesShipmentQuery |
|
862
|
|
|
*/ |
|
863
|
|
|
protected function applySalesShipmentFilters( |
|
864
|
|
|
SpySalesShipmentQuery $salesShipmentQuery, |
|
865
|
|
|
SalesShipmentCriteriaTransfer $salesShipmentCriteriaTransfer |
|
866
|
|
|
): SpySalesShipmentQuery { |
|
867
|
|
|
$salesShipmentConditionsTransfer = $salesShipmentCriteriaTransfer->getSalesShipmentConditions(); |
|
868
|
|
|
if ($salesShipmentConditionsTransfer === null) { |
|
869
|
|
|
return $salesShipmentQuery; |
|
870
|
|
|
} |
|
871
|
|
|
|
|
872
|
|
|
$orderItemUuids = $salesShipmentConditionsTransfer->getOrderItemUuids(); |
|
873
|
|
|
if ($orderItemUuids !== []) { |
|
874
|
|
|
$salesShipmentQuery->useSpySalesOrderItemQuery() |
|
875
|
|
|
->filterByUuid_In($orderItemUuids) |
|
876
|
|
|
->endUse() |
|
877
|
|
|
->distinct(); |
|
878
|
|
|
} |
|
879
|
|
|
|
|
880
|
|
|
$salesOrderItemIds = $salesShipmentConditionsTransfer->getSalesOrderItemIds(); |
|
881
|
|
|
if ($salesOrderItemIds !== []) { |
|
882
|
|
|
$salesShipmentQuery->useSpySalesOrderItemQuery() |
|
883
|
|
|
->filterByIdSalesOrderItem_In($salesOrderItemIds) |
|
884
|
|
|
->endUse() |
|
885
|
|
|
->distinct(); |
|
886
|
|
|
} |
|
887
|
|
|
|
|
888
|
|
|
$salesShipmentIds = $salesShipmentConditionsTransfer->getSalesShipmentIds(); |
|
889
|
|
|
if ($salesShipmentIds !== []) { |
|
890
|
|
|
$salesShipmentQuery->filterByIdSalesShipment_In($salesShipmentIds); |
|
891
|
|
|
} |
|
892
|
|
|
|
|
893
|
|
|
return $salesShipmentQuery; |
|
894
|
|
|
} |
|
895
|
|
|
|
|
896
|
|
|
/** |
|
897
|
|
|
* @module Store |
|
898
|
|
|
* |
|
899
|
|
|
* @param \Orm\Zed\Shipment\Persistence\SpyShipmentMethodQuery $shipmentMethodQuery |
|
900
|
|
|
* @param \Generated\Shared\Transfer\ShipmentMethodCriteriaTransfer $shipmentMethodCriteriaTransfer |
|
901
|
|
|
* |
|
902
|
|
|
* @return \Orm\Zed\Shipment\Persistence\SpyShipmentMethodQuery |
|
903
|
|
|
*/ |
|
904
|
|
|
protected function applyShipmentMethodFilters( |
|
905
|
|
|
SpyShipmentMethodQuery $shipmentMethodQuery, |
|
906
|
|
|
ShipmentMethodCriteriaTransfer $shipmentMethodCriteriaTransfer |
|
907
|
|
|
): SpyShipmentMethodQuery { |
|
908
|
|
|
$shipmentMethodConditionsTransfer = $shipmentMethodCriteriaTransfer->getShipmentMethodConditions(); |
|
909
|
|
|
if ($shipmentMethodConditionsTransfer === null) { |
|
910
|
|
|
return $shipmentMethodQuery; |
|
911
|
|
|
} |
|
912
|
|
|
|
|
913
|
|
|
if ($shipmentMethodConditionsTransfer->getShipmentMethodIds() !== []) { |
|
914
|
|
|
$shipmentMethodQuery->filterByIdShipmentMethod_In($shipmentMethodConditionsTransfer->getShipmentMethodIds()); |
|
915
|
|
|
} |
|
916
|
|
|
|
|
917
|
|
|
if ($shipmentMethodConditionsTransfer->getShipmentCarrierIds() !== []) { |
|
918
|
|
|
$shipmentMethodQuery->filterByFkShipmentCarrier_In($shipmentMethodConditionsTransfer->getShipmentCarrierIds()); |
|
919
|
|
|
} |
|
920
|
|
|
|
|
921
|
|
|
if ($shipmentMethodConditionsTransfer->getStoreNames() !== []) { |
|
922
|
|
|
$shipmentMethodQuery |
|
923
|
|
|
->groupByIdShipmentMethod() |
|
924
|
|
|
->useShipmentMethodStoreQuery() |
|
925
|
|
|
->useStoreQuery() |
|
926
|
|
|
->filterByName_In($shipmentMethodConditionsTransfer->getStoreNames()) |
|
927
|
|
|
->endUse() |
|
928
|
|
|
->endUse(); |
|
929
|
|
|
} |
|
930
|
|
|
|
|
931
|
|
|
if ($shipmentMethodConditionsTransfer->getIsActive() !== null) { |
|
932
|
|
|
$shipmentMethodQuery->filterByIsActive($shipmentMethodConditionsTransfer->getIsActiveOrFail()); |
|
933
|
|
|
} |
|
934
|
|
|
|
|
935
|
|
|
if ($shipmentMethodConditionsTransfer->getIsActiveShipmentCarrier() !== null) { |
|
936
|
|
|
$shipmentMethodQuery |
|
937
|
|
|
->useShipmentCarrierQuery() |
|
938
|
|
|
->filterByIsActive($shipmentMethodConditionsTransfer->getIsActiveShipmentCarrierOrFail()) |
|
939
|
|
|
->endUse(); |
|
940
|
|
|
} |
|
941
|
|
|
|
|
942
|
|
|
return $shipmentMethodQuery; |
|
943
|
|
|
} |
|
944
|
|
|
|
|
945
|
|
|
/** |
|
946
|
|
|
* @param \Propel\Runtime\ActiveQuery\ModelCriteria $query |
|
947
|
|
|
* @param \ArrayObject<array-key, \Generated\Shared\Transfer\SortTransfer> $sortTransfers |
|
948
|
|
|
* |
|
949
|
|
|
* @return \Propel\Runtime\ActiveQuery\ModelCriteria |
|
950
|
|
|
*/ |
|
951
|
|
|
protected function applySortingToQuery(ModelCriteria $query, ArrayObject $sortTransfers): ModelCriteria |
|
952
|
|
|
{ |
|
953
|
|
|
foreach ($sortTransfers as $sortTransfer) { |
|
954
|
|
|
$query->orderBy( |
|
955
|
|
|
$sortTransfer->getFieldOrFail(), |
|
956
|
|
|
$sortTransfer->getIsAscending() ? Criteria::ASC : Criteria::DESC, |
|
957
|
|
|
); |
|
958
|
|
|
} |
|
959
|
|
|
|
|
960
|
|
|
return $query; |
|
961
|
|
|
} |
|
962
|
|
|
|
|
963
|
|
|
/** |
|
964
|
|
|
* @param \Propel\Runtime\ActiveQuery\ModelCriteria $query |
|
965
|
|
|
* @param \Generated\Shared\Transfer\PaginationTransfer $paginationTransfer |
|
966
|
|
|
* |
|
967
|
|
|
* @return \Propel\Runtime\ActiveQuery\ModelCriteria |
|
968
|
|
|
*/ |
|
969
|
|
|
protected function applyPaginationToQuery( |
|
970
|
|
|
ModelCriteria $query, |
|
971
|
|
|
PaginationTransfer $paginationTransfer |
|
972
|
|
|
): ModelCriteria { |
|
973
|
|
|
if ($paginationTransfer->getOffset() !== null && $paginationTransfer->getLimit() !== null) { |
|
974
|
|
|
$paginationTransfer->setNbResults($query->count()); |
|
975
|
|
|
|
|
976
|
|
|
$query->offset($paginationTransfer->getOffsetOrFail()) |
|
977
|
|
|
->setLimit($paginationTransfer->getLimitOrFail()); |
|
978
|
|
|
|
|
979
|
|
|
return $query; |
|
980
|
|
|
} |
|
981
|
|
|
|
|
982
|
|
|
if ($paginationTransfer->getPage() !== null && $paginationTransfer->getMaxPerPage() !== null) { |
|
983
|
|
|
$paginationModel = $query->paginate( |
|
984
|
|
|
$paginationTransfer->getPageOrFail(), |
|
985
|
|
|
$paginationTransfer->getMaxPerPageOrFail(), |
|
986
|
|
|
); |
|
987
|
|
|
|
|
988
|
|
|
$this->getFactory()->createPaginationMapper()->mapPropelModelPagerToPaginationTransfer( |
|
989
|
|
|
$paginationModel, |
|
990
|
|
|
$paginationTransfer, |
|
991
|
|
|
); |
|
992
|
|
|
|
|
993
|
|
|
return $paginationModel->getQuery(); |
|
994
|
|
|
} |
|
995
|
|
|
|
|
996
|
|
|
return $query; |
|
997
|
|
|
} |
|
998
|
|
|
} |
|
999
|
|
|
|