Passed
Push — 6.4 ( 969936...be76f2 )
by Christian
44:06 queued 29:02
created

OrderConverter   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 393
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 213
dl 0
loc 393
rs 6.96
c 1
b 0
f 0
wmc 53

5 Methods

Rating   Name   Duplication   Size   Complexity  
B convertToCart() 0 49 7
B convertDeliveries() 0 68 10
F assembleSalesChannelContext() 0 88 19
A __construct() 0 18 1
F convertToOrder() 0 103 16

How to fix   Complexity   

Complex Class

Complex classes like OrderConverter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use OrderConverter, and based on these observations, apply Extract Interface, too.

1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Cart\Order;
4
5
use Shopware\Core\Checkout\Cart\Cart;
6
use Shopware\Core\Checkout\Cart\CartException;
7
use Shopware\Core\Checkout\Cart\Delivery\DeliveryProcessor;
8
use Shopware\Core\Checkout\Cart\Delivery\Struct\Delivery;
9
use Shopware\Core\Checkout\Cart\Delivery\Struct\DeliveryCollection;
10
use Shopware\Core\Checkout\Cart\Delivery\Struct\DeliveryDate;
11
use Shopware\Core\Checkout\Cart\Delivery\Struct\DeliveryPosition;
12
use Shopware\Core\Checkout\Cart\Delivery\Struct\DeliveryPositionCollection;
13
use Shopware\Core\Checkout\Cart\Delivery\Struct\ShippingLocation;
14
use Shopware\Core\Checkout\Cart\Exception\InvalidPayloadException;
15
use Shopware\Core\Checkout\Cart\Exception\InvalidQuantityException;
16
use Shopware\Core\Checkout\Cart\Exception\LineItemNotStackableException;
17
use Shopware\Core\Checkout\Cart\Exception\MissingOrderRelationException;
18
use Shopware\Core\Checkout\Cart\Exception\MixedLineItemTypeException;
19
use Shopware\Core\Checkout\Cart\Exception\OrderInconsistentException;
20
use Shopware\Core\Checkout\Cart\LineItem\LineItemCollection;
21
use Shopware\Core\Checkout\Cart\Order\Transformer\AddressTransformer;
22
use Shopware\Core\Checkout\Cart\Order\Transformer\CartTransformer;
23
use Shopware\Core\Checkout\Cart\Order\Transformer\CustomerTransformer;
24
use Shopware\Core\Checkout\Cart\Order\Transformer\DeliveryTransformer;
25
use Shopware\Core\Checkout\Cart\Order\Transformer\LineItemTransformer;
26
use Shopware\Core\Checkout\Cart\Order\Transformer\TransactionTransformer;
27
use Shopware\Core\Checkout\Customer\CustomerEntity;
28
use Shopware\Core\Checkout\Customer\Exception\AddressNotFoundException;
29
use Shopware\Core\Checkout\Order\Aggregate\OrderAddress\OrderAddressEntity;
30
use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryCollection;
31
use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryStates;
32
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates;
33
use Shopware\Core\Checkout\Order\Exception\DeliveryWithoutAddressException;
34
use Shopware\Core\Checkout\Order\OrderDefinition;
35
use Shopware\Core\Checkout\Order\OrderEntity;
36
use Shopware\Core\Checkout\Order\OrderException;
37
use Shopware\Core\Checkout\Order\OrderStates;
38
use Shopware\Core\Checkout\Promotion\Cart\PromotionCollector;
39
use Shopware\Core\Content\Product\Cart\ProductCartProcessor;
40
use Shopware\Core\Framework\Context;
41
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
42
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
43
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
44
use Shopware\Core\Framework\Feature;
45
use Shopware\Core\Framework\Log\Package;
46
use Shopware\Core\Framework\Uuid\Uuid;
47
use Shopware\Core\System\NumberRange\ValueGenerator\NumberRangeValueGeneratorInterface;
48
use Shopware\Core\System\SalesChannel\Context\AbstractSalesChannelContextFactory;
49
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService;
50
use Shopware\Core\System\SalesChannel\SalesChannelContext;
51
use Shopware\Core\System\StateMachine\Loader\InitialStateIdLoader;
52
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
53
54
#[Package('checkout')]
55
class OrderConverter
56
{
57
    public const CART_CONVERTED_TO_ORDER_EVENT = 'cart.convertedToOrder.event';
58
59
    public const CART_TYPE = 'recalculation';
60
61
    public const ORIGINAL_ID = 'originalId';
62
63
    public const ORIGINAL_ORDER_NUMBER = 'originalOrderNumber';
64
65
    public const ORIGINAL_DOWNLOADS = 'originalDownloads';
66
67
    public const ADMIN_EDIT_ORDER_PERMISSIONS = [
68
        ProductCartProcessor::ALLOW_PRODUCT_PRICE_OVERWRITES => true,
69
        ProductCartProcessor::SKIP_PRODUCT_RECALCULATION => true,
70
        DeliveryProcessor::SKIP_DELIVERY_PRICE_RECALCULATION => true,
71
        DeliveryProcessor::SKIP_DELIVERY_TAX_RECALCULATION => true,
72
        PromotionCollector::SKIP_PROMOTION => true,
73
        ProductCartProcessor::SKIP_PRODUCT_STOCK_VALIDATION => true,
74
        ProductCartProcessor::KEEP_INACTIVE_PRODUCT => true,
75
    ];
76
77
    protected EntityRepositoryInterface $customerRepository;
78
79
    protected AbstractSalesChannelContextFactory $salesChannelContextFactory;
80
81
    protected EventDispatcherInterface $eventDispatcher;
82
83
    private NumberRangeValueGeneratorInterface $numberRangeValueGenerator;
84
85
    private OrderDefinition $orderDefinition;
86
87
    private EntityRepositoryInterface $orderAddressRepository;
88
89
    private InitialStateIdLoader $initialStateIdLoader;
90
91
    private LineItemDownloadLoader $downloadLoader;
92
93
    /**
94
     * @internal
95
     */
96
    public function __construct(
97
        EntityRepositoryInterface $customerRepository,
98
        AbstractSalesChannelContextFactory $salesChannelContextFactory,
99
        EventDispatcherInterface $eventDispatcher,
100
        NumberRangeValueGeneratorInterface $numberRangeValueGenerator,
101
        OrderDefinition $orderDefinition,
102
        EntityRepositoryInterface $orderAddressRepository,
103
        InitialStateIdLoader $initialStateIdLoader,
104
        LineItemDownloadLoader $downloadLoader
105
    ) {
106
        $this->customerRepository = $customerRepository;
107
        $this->salesChannelContextFactory = $salesChannelContextFactory;
108
        $this->eventDispatcher = $eventDispatcher;
109
        $this->numberRangeValueGenerator = $numberRangeValueGenerator;
110
        $this->orderDefinition = $orderDefinition;
111
        $this->orderAddressRepository = $orderAddressRepository;
112
        $this->initialStateIdLoader = $initialStateIdLoader;
113
        $this->downloadLoader = $downloadLoader;
114
    }
115
116
    /**
117
     * @throws DeliveryWithoutAddressException
118
     *
119
     * @return array<string, mixed|float|string|array<int, array<string, string|int|bool|mixed>>|null>
120
     */
121
    public function convertToOrder(Cart $cart, SalesChannelContext $context, OrderConversionContext $conversionContext): array
122
    {
123
        foreach ($cart->getDeliveries() as $delivery) {
124
            if ($delivery->getLocation()->getAddress() !== null || $delivery->hasExtensionOfType(self::ORIGINAL_ID, IdStruct::class)) {
125
                continue;
126
            }
127
128
            throw new DeliveryWithoutAddressException();
129
        }
130
        $data = CartTransformer::transform(
131
            $cart,
132
            $context,
133
            $this->initialStateIdLoader->get(OrderStates::STATE_MACHINE),
134
            $conversionContext->shouldIncludeOrderDate()
135
        );
136
137
        if ($conversionContext->shouldIncludeCustomer()) {
138
            $customer = $context->getCustomer();
139
            if ($customer === null) {
140
                throw CartException::customerNotLoggedIn();
141
            }
142
143
            $data['orderCustomer'] = CustomerTransformer::transform($customer);
144
        }
145
146
        $data['languageId'] = $context->getLanguageId();
147
148
        $convertedLineItems = LineItemTransformer::transformCollection($cart->getLineItems());
149
        $shippingAddresses = [];
150
151
        if ($conversionContext->shouldIncludeDeliveries()) {
152
            $shippingAddresses = AddressTransformer::transformCollection($cart->getDeliveries()->getAddresses(), true);
153
            $data['deliveries'] = DeliveryTransformer::transformCollection(
154
                $cart->getDeliveries(),
155
                $convertedLineItems,
156
                $this->initialStateIdLoader->get(OrderDeliveryStates::STATE_MACHINE),
157
                $context->getContext(),
158
                $shippingAddresses
159
            );
160
        }
161
162
        if ($conversionContext->shouldIncludeBillingAddress()) {
163
            $customer = $context->getCustomer();
164
            if ($customer === null) {
165
                throw CartException::customerNotLoggedIn();
166
            }
167
168
            $activeBillingAddress = $customer->getActiveBillingAddress();
169
            if ($activeBillingAddress === null) {
170
                throw new AddressNotFoundException('');
171
            }
172
            $customerAddressId = $activeBillingAddress->getId();
173
174
            if (\array_key_exists($customerAddressId, $shippingAddresses)) {
175
                $billingAddressId = $shippingAddresses[$customerAddressId]['id'];
176
            } else {
177
                $billingAddress = AddressTransformer::transform($activeBillingAddress);
178
                $data['addresses'] = [$billingAddress];
179
                $billingAddressId = $billingAddress['id'];
180
            }
181
            $data['billingAddressId'] = $billingAddressId;
182
        }
183
184
        if ($conversionContext->shouldIncludeTransactions()) {
185
            $data['transactions'] = TransactionTransformer::transformCollection(
186
                $cart->getTransactions(),
187
                $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE),
188
                $context->getContext()
189
            );
190
        }
191
192
        $data['lineItems'] = array_values($convertedLineItems);
193
194
        foreach ($this->downloadLoader->load($data['lineItems'], $context->getContext()) as $key => $downloads) {
195
            if (!\array_key_exists($key, $data['lineItems'])) {
196
                continue;
197
            }
198
199
            $data['lineItems'][$key]['downloads'] = $downloads;
200
        }
201
202
        /** @var IdStruct|null $idStruct */
203
        $idStruct = $cart->getExtensionOfType(self::ORIGINAL_ID, IdStruct::class);
204
        $data['id'] = $idStruct ? $idStruct->getId() : Uuid::randomHex();
0 ignored issues
show
introduced by
$idStruct is of type Shopware\Core\Checkout\Cart\Order\IdStruct, thus it always evaluated to true.
Loading history...
205
206
        /** @var IdStruct|null $orderNumberStruct */
207
        $orderNumberStruct = $cart->getExtensionOfType(self::ORIGINAL_ORDER_NUMBER, IdStruct::class);
208
        if ($orderNumberStruct !== null) {
209
            $data['orderNumber'] = $orderNumberStruct->getId();
210
        } else {
211
            $data['orderNumber'] = $this->numberRangeValueGenerator->getValue(
212
                $this->orderDefinition->getEntityName(),
213
                $context->getContext(),
214
                $context->getSalesChannel()->getId()
215
            );
216
        }
217
218
        $data['ruleIds'] = $context->getRuleIds();
219
220
        $event = new CartConvertedEvent($cart, $data, $context, $conversionContext);
221
        $this->eventDispatcher->dispatch($event);
222
223
        return $event->getConvertedCart();
224
    }
225
226
    /**
227
     * @throws InvalidPayloadException
228
     * @throws InvalidQuantityException
229
     * @throws LineItemNotStackableException
230
     * @throws MixedLineItemTypeException
231
     * @throws MissingOrderRelationException
232
     */
233
    public function convertToCart(OrderEntity $order, Context $context): Cart
234
    {
235
        if ($order->getLineItems() === null) {
236
            if (Feature::isActive('v6.5.0.0')) {
237
                throw OrderException::missingAssociation('lineItems');
238
            }
239
240
            throw new MissingOrderRelationException('lineItems');
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...gOrderRelationException has been deprecated: tag:v6.5.0 - Will be removed. Use \Shopware\Core\Checkout\Cart\CartException::missingAssociation instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

240
            throw /** @scrutinizer ignore-deprecated */ new MissingOrderRelationException('lineItems');
Loading history...
241
        }
242
243
        if ($order->getDeliveries() === null) {
244
            if (Feature::isActive('v6.5.0.0')) {
245
                throw OrderException::missingAssociation('deliveries');
246
            }
247
248
            throw new MissingOrderRelationException('deliveries');
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...gOrderRelationException has been deprecated: tag:v6.5.0 - Will be removed. Use \Shopware\Core\Checkout\Cart\CartException::missingAssociation instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

248
            throw /** @scrutinizer ignore-deprecated */ new MissingOrderRelationException('deliveries');
Loading history...
249
        }
250
251
        $cart = new Cart(self::CART_TYPE, Uuid::randomHex());
252
        $cart->setPrice($order->getPrice());
253
        $cart->setCustomerComment($order->getCustomerComment());
254
        $cart->setAffiliateCode($order->getAffiliateCode());
255
        $cart->setCampaignCode($order->getCampaignCode());
256
        $cart->addExtension(self::ORIGINAL_ID, new IdStruct($order->getId()));
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Core\Framework\...\Struct::addExtension() has been deprecated: tag:v6.5.0 - second param $extension will not allow null anymore ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

256
        /** @scrutinizer ignore-deprecated */ $cart->addExtension(self::ORIGINAL_ID, new IdStruct($order->getId()));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
257
        $orderNumber = $order->getOrderNumber();
258
        if ($orderNumber === null) {
0 ignored issues
show
introduced by
The condition $orderNumber === null is always false.
Loading history...
259
            if (Feature::isActive('v6.5.0.0')) {
260
                throw OrderException::missingOrderNumber($order->getId());
261
            }
262
263
            throw new OrderInconsistentException($order->getId(), 'orderNumber is required');
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...erInconsistentException has been deprecated: tag:v6.5.0 - Will be removed. Use \Shopware\Core\Checkout\Cart\CartException::missingOrderNumber instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

263
            throw /** @scrutinizer ignore-deprecated */ new OrderInconsistentException($order->getId(), 'orderNumber is required');
Loading history...
264
        }
265
266
        $cart->addExtension(self::ORIGINAL_ORDER_NUMBER, new IdStruct($orderNumber));
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Core\Framework\...\Struct::addExtension() has been deprecated: tag:v6.5.0 - second param $extension will not allow null anymore ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

266
        /** @scrutinizer ignore-deprecated */ $cart->addExtension(self::ORIGINAL_ORDER_NUMBER, new IdStruct($orderNumber));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
267
        /* NEXT-708 support:
268
            - transactions
269
        */
270
271
        $lineItems = LineItemTransformer::transformFlatToNested($order->getLineItems());
272
273
        $cart->addLineItems($lineItems);
274
        $cart->setDeliveries(
275
            $this->convertDeliveries($order->getDeliveries(), $lineItems)
276
        );
277
278
        $event = new OrderConvertedEvent($order, $cart, $context);
279
        $this->eventDispatcher->dispatch($event);
280
281
        return $event->getConvertedCart();
282
    }
283
284
    /**
285
     * @param array<string, array<string, bool>|string> $overrideOptions
286
     *
287
     * @throws InconsistentCriteriaIdsException
288
     */
289
    public function assembleSalesChannelContext(OrderEntity $order, Context $context, array $overrideOptions = []): SalesChannelContext
290
    {
291
        if ($order->getTransactions() === null) {
292
            if (Feature::isActive('v6.5.0.0')) {
293
                throw OrderException::missingAssociation('transactions');
294
            }
295
296
            throw new MissingOrderRelationException('transactions');
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...gOrderRelationException has been deprecated: tag:v6.5.0 - Will be removed. Use \Shopware\Core\Checkout\Cart\CartException::missingAssociation instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

296
            throw /** @scrutinizer ignore-deprecated */ new MissingOrderRelationException('transactions');
Loading history...
297
        }
298
        if ($order->getOrderCustomer() === null) {
299
            if (Feature::isActive('v6.5.0.0')) {
300
                throw OrderException::missingAssociation('orderCustomer');
301
            }
302
303
            throw new MissingOrderRelationException('orderCustomer');
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...gOrderRelationException has been deprecated: tag:v6.5.0 - Will be removed. Use \Shopware\Core\Checkout\Cart\CartException::missingAssociation instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

303
            throw /** @scrutinizer ignore-deprecated */ new MissingOrderRelationException('orderCustomer');
Loading history...
304
        }
305
306
        $customerId = $order->getOrderCustomer()->getCustomerId();
307
        $customerGroupId = null;
308
309
        if ($customerId) {
310
            /** @var CustomerEntity|null $customer */
311
            $customer = $this->customerRepository->search(new Criteria([$customerId]), $context)->get($customerId);
312
            if ($customer !== null) {
313
                $customerGroupId = $customer->getGroupId();
314
            }
315
        }
316
317
        $billingAddressId = $order->getBillingAddressId();
318
        /** @var OrderAddressEntity|null $billingAddress */
319
        $billingAddress = $this->orderAddressRepository->search(new Criteria([$billingAddressId]), $context)->get($billingAddressId);
320
        if ($billingAddress === null) {
321
            throw new AddressNotFoundException($billingAddressId);
322
        }
323
324
        $options = [
325
            SalesChannelContextService::CURRENCY_ID => $order->getCurrencyId(),
326
            SalesChannelContextService::LANGUAGE_ID => $order->getLanguageId(),
327
            SalesChannelContextService::CUSTOMER_ID => $customerId,
328
            SalesChannelContextService::COUNTRY_STATE_ID => $billingAddress->getCountryStateId(),
329
            SalesChannelContextService::CUSTOMER_GROUP_ID => $customerGroupId,
330
            SalesChannelContextService::PERMISSIONS => self::ADMIN_EDIT_ORDER_PERMISSIONS,
331
            SalesChannelContextService::VERSION_ID => $context->getVersionId(),
332
        ];
333
334
        $delivery = $order->getDeliveries() !== null ? $order->getDeliveries()->first() : null;
335
        if ($delivery !== null) {
336
            $options[SalesChannelContextService::SHIPPING_METHOD_ID] = $delivery->getShippingMethodId();
337
        }
338
339
        //get the first not paid transaction and not cancelled or, if all paid or cancelled, the last transaction
340
        if ($order->getTransactions() !== null) {
341
            foreach ($order->getTransactions() as $transaction) {
342
                $options[SalesChannelContextService::PAYMENT_METHOD_ID] = $transaction->getPaymentMethodId();
343
                if (
344
                    $transaction->getStateMachineState() !== null
345
                    && $transaction->getStateMachineState()->getTechnicalName() !== OrderTransactionStates::STATE_PAID
346
                    && $transaction->getStateMachineState()->getTechnicalName() !== OrderTransactionStates::STATE_CANCELLED
347
                ) {
348
                    break;
349
                }
350
            }
351
        }
352
353
        $options = array_merge($options, $overrideOptions);
354
355
        $salesChannelContext = $this->salesChannelContextFactory->create(Uuid::randomHex(), $order->getSalesChannelId(), $options);
356
        $salesChannelContext->getContext()->addExtensions($context->getExtensions());
357
        $salesChannelContext->addState(...$context->getStates());
358
        $salesChannelContext->setTaxState($order->getTaxStatus());
359
360
        if ($context->hasState(Context::SKIP_TRIGGER_FLOW)) {
361
            $salesChannelContext->getContext()->addState(Context::SKIP_TRIGGER_FLOW);
362
        }
363
364
        if ($order->getItemRounding() !== null) {
365
            $salesChannelContext->setItemRounding($order->getItemRounding());
366
        }
367
368
        if ($order->getTotalRounding() !== null) {
369
            $salesChannelContext->setTotalRounding($order->getTotalRounding());
370
        }
371
372
        if ($order->getRuleIds() !== null) {
373
            $salesChannelContext->setRuleIds($order->getRuleIds());
374
        }
375
376
        return $salesChannelContext;
377
    }
378
379
    private function convertDeliveries(OrderDeliveryCollection $orderDeliveries, LineItemCollection $lineItems): DeliveryCollection
380
    {
381
        $cartDeliveries = new DeliveryCollection();
382
383
        foreach ($orderDeliveries as $orderDelivery) {
384
            $deliveryDate = new DeliveryDate(
385
                $orderDelivery->getShippingDateEarliest(),
386
                $orderDelivery->getShippingDateLatest()
387
            );
388
389
            $deliveryPositions = new DeliveryPositionCollection();
390
391
            if ($orderDelivery->getPositions() === null) {
392
                continue;
393
            }
394
395
            foreach ($orderDelivery->getPositions() as $position) {
396
                if ($position->getOrderLineItem() === null) {
397
                    continue;
398
                }
399
400
                $identifier = $position->getOrderLineItem()->getIdentifier();
401
402
                // line item has been removed and will not be added to delivery
403
                if ($lineItems->get($identifier) === null) {
404
                    continue;
405
                }
406
407
                if ($position->getPrice() === null) {
408
                    continue;
409
                }
410
411
                $deliveryPosition = new DeliveryPosition(
412
                    $identifier,
413
                    $lineItems->get($identifier),
0 ignored issues
show
Bug introduced by
It seems like $lineItems->get($identifier) can also be of type null; however, parameter $lineItem of Shopware\Core\Checkout\C...Position::__construct() does only seem to accept Shopware\Core\Checkout\Cart\LineItem\LineItem, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

413
                    /** @scrutinizer ignore-type */ $lineItems->get($identifier),
Loading history...
414
                    $position->getPrice()->getQuantity(),
415
                    $position->getPrice(),
416
                    $deliveryDate
417
                );
418
                $deliveryPosition->addExtension(self::ORIGINAL_ID, new IdStruct($position->getId()));
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Core\Framework\...\Struct::addExtension() has been deprecated: tag:v6.5.0 - second param $extension will not allow null anymore ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

418
                /** @scrutinizer ignore-deprecated */ $deliveryPosition->addExtension(self::ORIGINAL_ID, new IdStruct($position->getId()));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
419
420
                $deliveryPositions->add($deliveryPosition);
421
            }
422
423
            if ($orderDelivery->getShippingMethod() === null
424
                || $orderDelivery->getShippingOrderAddress() === null
425
                || $orderDelivery->getShippingOrderAddress()->getCountry() === null
426
            ) {
427
                continue;
428
            }
429
430
            $cartDelivery = new Delivery(
431
                $deliveryPositions,
432
                $deliveryDate,
433
                $orderDelivery->getShippingMethod(),
434
                new ShippingLocation(
435
                    $orderDelivery->getShippingOrderAddress()->getCountry(),
436
                    $orderDelivery->getShippingOrderAddress()->getCountryState(),
437
                    null
438
                ),
439
                $orderDelivery->getShippingCosts()
440
            );
441
            $cartDelivery->addExtension(self::ORIGINAL_ID, new IdStruct($orderDelivery->getId()));
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Core\Framework\...\Struct::addExtension() has been deprecated: tag:v6.5.0 - second param $extension will not allow null anymore ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

441
            /** @scrutinizer ignore-deprecated */ $cartDelivery->addExtension(self::ORIGINAL_ID, new IdStruct($orderDelivery->getId()));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
442
443
            $cartDeliveries->add($cartDelivery);
444
        }
445
446
        return $cartDeliveries;
447
    }
448
}
449