DeliveryPosition example

$this->deliveryCalculator->calculate(new CartDataCollection()new Cart('test')new DeliveryCollection()$context);
    }

    public function testCalculateWithAlreadyCalculatedCosts(): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getContext')->willReturn(Context::createDefaultContext());
        $context->method('getItemRounding')->willReturn(new CashRoundingConfig(2, 0.01, true));

        $positions = new DeliveryPositionCollection();
        $positions->add(
            new DeliveryPosition(
                Uuid::randomHex(),
                new LineItem('test', 'test'),
                1,
                new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()),
                new DeliveryDate(new \DateTime()new \DateTime())
            )
        );

        $shippingMethod = new ShippingMethodEntity();
        $shippingMethod->setTaxType(ShippingMethodEntity::TAX_TYPE_AUTO);
        $delivery = new Delivery(
            
// if the line item has a restock time, add this days to the restock date             if ($restockTime) {
                $restockDate = $restockDate->add(new \DateInterval('P' . $restockTime . 'D'));
            }

            if ($item->getPrice() === null) {
                continue;
            }

            // if the item is completely in stock, use the delivery date             if ($item->getDeliveryInformation()->getStock() >= $item->getQuantity()) {
                $position = new DeliveryPosition($item->getId()clone $item$item->getQuantity()clone $item->getPrice()$deliveryDate);
            } else {
                // otherwise use the restock date as delivery date                 $position = new DeliveryPosition($item->getId()clone $item$item->getQuantity()clone $item->getPrice()$restockDate);
            }

            $positions->add($position);
        }
    }
}
$this->createLineItemWithDeliveryInfo(false, 3, 10, 40, 3, 0.5),
            $this->createLineItemWithDeliveryInfo(true, 3, 10, 40, 3, 0.5),
        ]);

        $cart = $this->createCart($lineItemCollection);

        $deliveryPositionCollection = new DeliveryPositionCollection();
        $calculatedPrice = new CalculatedPrice(1.0, 1.0, new CalculatedTaxCollection()new TaxRuleCollection());
        $deliveryDate = new DeliveryDate(new \DateTimeImmutable('now')new \DateTimeImmutable('now'));

        foreach ($cart->getLineItems() as $lineItem) {
            $deliveryPositionCollection->add(new DeliveryPosition(
                Uuid::randomHex(),
                $lineItem,
                $lineItem->getQuantity(),
                $calculatedPrice,
                $deliveryDate
            ));
        }

        $cart->setDeliveries(new DeliveryCollection(
            [
                new Delivery(
                    


        /** @var Delivery $delivery */
        $delivery = $cart->getDeliveries()->first();
        if (!$delivery) {
            return;
        }

        $calculatedPrice = $item->getPrice();
        \assert($calculatedPrice instanceof CalculatedPrice);

        $position = new DeliveryPosition($item->getId()clone $item$item->getQuantity()$calculatedPrice$delivery->getDeliveryDate());

        $delivery->getPositions()->add($position);
    }

    private function fetchOrder(string $orderId, Context $context): ?OrderEntity
    {
        $criteria = (new Criteria([$orderId]))
            ->addAssociation('lineItems.downloads')
            ->addAssociation('transactions.stateMachineState')
            ->addAssociation('deliveries.shippingMethod')
            ->addAssociation('deliveries.positions.orderLineItem')
            
$taxes,
            new TaxRuleCollection(),
            1
        );

        $lineItem->setPrice($calculatedPrice);
        $cart->add($lineItem);

        $deliveries = new DeliveryCollection([
            new Delivery(
                new DeliveryPositionCollection([
                    new DeliveryPosition(
                        $this->ids->get('delivery-position-1'),
                        $lineItem,
                        1,
                        clone $calculatedPrice,
                        new DeliveryDate(new \DateTimeImmutable()new \DateTimeImmutable())
                    ),
                ]),
                new DeliveryDate(new \DateTimeImmutable()new \DateTimeImmutable()),
                new ShippingMethodEntity(),
                new ShippingLocation(new CountryEntity()new CountryStateEntity(), null),
                clone $calculatedPrice
            ),
$cart = (new Cart('test'))->add(self::coverItem($id$thumbnailString$skipCover));
        $cart->addDeliveries(self::itemDelivery(self::coverItem($id$thumbnailString$skipCover)));

        return $cart;
    }

    private static function itemDelivery(LineItem $lineItem): DeliveryCollection
    {
        $delivery = new Delivery(
            new DeliveryPositionCollection(
                [
                    new DeliveryPosition(
                        $lineItem->getId(),
                        $lineItem,
                        1,
                        new CalculatedPrice(1.0, 1.0, new CalculatedTaxCollection()new TaxRuleCollection()),
                        new DeliveryDate(new \DateTimeImmutable()new \DateTimeImmutable())
                    ),
                ]
            ),
            new DeliveryDate(new \DateTimeImmutable()new \DateTimeImmutable()),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            
null,
                $this->deliveryTime
            )
        );
        $lineItem->setPrice(new CalculatedPrice(1, 1, new CalculatedTaxCollection()new TaxRuleCollection()));
        $price = $lineItem->getPrice();
        static::assertNotNull($price);

        $delivery->expects(static::once())->method('getPositions')->willReturn(
            new DeliveryPositionCollection(
                [
                    new DeliveryPosition(
                        Uuid::randomHex(),
                        $lineItem,
                        1,
                        $price,
                        new DeliveryDate(new \DateTime()new \DateTime())
                    ),
                ]
            )
        );

        $data = new CartDataCollection();

        

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithDeliveryInfo(false, 3, 10, 40, 3, 0.5),
            $this->createLineItemWithDeliveryInfo(true, 3, 10, 40, 3, 0.5),
        ]);

        $cart = $this->createCart($lineItemCollection);
        $deliveryPositionCollection = new DeliveryPositionCollection();
        $deliveryDate = new DeliveryDate(new \DateTimeImmutable('now')new \DateTimeImmutable('now'));

        foreach ($cart->getLineItems() as $lineItem) {
            $deliveryPositionCollection->add(new DeliveryPosition(
                Uuid::randomHex(),
                $lineItem,
                $lineItem->getQuantity(),
                $calculatedPrice,
                $deliveryDate
            ));
        }

        $cart->setDeliveries(new DeliveryCollection(
            [
                new Delivery(
                    
class DeliveryPositionCollectionTest extends TestCase
{
    public function testCalculateWithMultipleQuantityLineItem(): void
    {
        $deliveryPositionCollection = new DeliveryPositionCollection();

        $lineItem = $this->getLineItem(10, 2);

        /** @var CalculatedPrice $price */
        $price = $lineItem->getPrice();
        $deliveryPositionCollection->add(
            new DeliveryPosition(
                Uuid::randomHex(),
                $lineItem,
                $lineItem->getQuantity(),
                $price,
                new DeliveryDate(new \DateTimeImmutable('2020-01-01')new \DateTimeImmutable('2020-01-01')),
            )
        );

        static::assertEquals(20, $deliveryPositionCollection->getWeight());
    }

    
$identifier = $position->getOrderLineItem()->getIdentifier();

                // line item has been removed and will not be added to delivery                 if ($lineItems->get($identifier) === null) {
                    continue;
                }

                if ($position->getPrice() === null) {
                    continue;
                }

                $deliveryPosition = new DeliveryPosition(
                    $identifier,
                    $lineItems->get($identifier),
                    $position->getPrice()->getQuantity(),
                    $position->getPrice(),
                    $deliveryDate
                );
                $deliveryPosition->addExtension(self::ORIGINAL_ID, new IdStruct($position->getId()));

                $deliveryPositions->add($deliveryPosition);
            }

            
1
        );

        $price->assign(['calculatedTaxes' => $taxes]);
        $lineItem->setPrice($price);

        $cart->add($lineItem);

        $deliveries = new DeliveryCollection([
            new Delivery(
                new DeliveryPositionCollection([
                    new DeliveryPosition(
                        $this->ids->get('delivery-position-1'),
                        $lineItem,
                        1,
                        $price,
                        static::createMock(DeliveryDate::class)
                    ),
                ]),
                static::createMock(DeliveryDate::class),
                static::createMock(ShippingMethodEntity::class),
                static::createMock(ShippingLocation::class),
                $price
            ),
Home | Imprint | This part of the site doesn't use cookies.