DeliveryInformation example

protected static function createLineItemWithDeliveryInfo(
        bool $freeDelivery,
        int $quantity = 1,
        ?float $weight = 50.0,
        ?float $height = null,
        ?float $width = null,
        ?float $length = null,
        int $stock = 9999
    ): LineItem {
        return self::createLineItem(LineItem::PRODUCT_LINE_ITEM_TYPE, $quantity)->setDeliveryInformation(
            new DeliveryInformation(
                $stock,
                $weight,
                $freeDelivery,
                null,
                (new DeliveryTime())->assign([
                    'min' => 1,
                    'max' => 3,
                    'unit' => 'weeks',
                    'name' => '1-3 weeks',
                ]),
                $height,
                
'free item' => [true],
            'not free item' => [false],
            'no delivery information' => [null],
        ];
    }

    private function getLineItem(?bool $freeDelivery = null): LineItem
    {
        $lineItem = new LineItem(Uuid::randomHex(), LineItem::PRODUCT_LINE_ITEM_TYPE);

        if ($freeDelivery !== null) {
            $lineItem->setDeliveryInformation(new DeliveryInformation(3, null, $freeDelivery));
        }

        return $lineItem;
    }
}
$delivery = $this->getMockBuilder(Delivery::class)
            ->disableOriginalConstructor()
            ->getMock();
        $costs = new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection());
        $delivery->expects(static::atLeastOnce())->method('getShippingCosts')->willReturn($costs);
        $delivery->expects(static::never())->method('setShippingCosts');
        $delivery->expects(static::atLeastOnce())->method('getShippingMethod')->willReturn($shippingMethod);

        $lineItem = new LineItem(Uuid::randomHex(), 'product');
        $lineItem->setDeliveryInformation(
            new DeliveryInformation(
                10,
                12.0,
                false,
                null,
                $this->deliveryTime
            )
        );
        $lineItem->setPrice(new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()));
        $price = $lineItem->getPrice();
        static::assertNotNull($price);

        
public static function getLineItemsThatResultInAnEmptyDelivery(): iterable
    {
        yield 'DeliveryCollection is empty if LineItemCollection is empty' => [new LineItemCollection()];

        yield 'DeliveryCollection is empty if no LineItem has set deliveryInformation' => [new LineItemCollection([
            (new LineItem('line-item-id', LineItem::CUSTOM_LINE_ITEM_TYPE, null, 1))
                ->assign(['deliveryInformation' => null]),
        ])];

        yield 'DeliveryCollection is empty if LineItems deliveryTime is null' => [new LineItemCollection([
            (new LineItem('line-item-id', LineItem::CUSTOM_LINE_ITEM_TYPE, null, 1))
                ->assign(['deliveryInformation' => new DeliveryInformation(10, 1, false, null, null)]),
        ])];

        $deliveryTime = self::createDeliveryTime(1, 3);

        yield 'DeliveryCollection is empty if LineItems price is not set' => [new LineItemCollection([
            (new LineItem('line-item-id', LineItem::CUSTOM_LINE_ITEM_TYPE, null, 1))
                ->assign([
                    'deliveryInformation' => new DeliveryInformation(10, 1, false, 5, $deliveryTime),
                    'price' => null,
                ]),
        ])];
    }
$price = new CalculatedPrice(100, 200, new CalculatedTaxCollection()new TaxRuleCollection());
        $lineItem->setPrice($price);

        return $lineItem;
    }

    private function createDeliveryInformation(): DeliveryInformation
    {
        $deliveryTime = $this->createDeliveryTime();

        return new DeliveryInformation(100, 10.0, false, null, $deliveryTime);
    }

    private function createDeliveryTime(): DeliveryTime
    {
        $deliveryTime = new DeliveryTime();
        $deliveryTime->setMin(2);
        $deliveryTime->setMax(2);
        $deliveryTime->setUnit(DeliveryTimeEntity::DELIVERY_TIME_MONTH);

        return $deliveryTime;
    }
}
private function getLineItem(
        float $weight = 10.0,
        int $quantity = 1,
        bool $freeDelivery = true,
        ?float $height = null,
        ?float $width = null,
        ?float $length = null
    ): LineItem {
        return (new LineItem(Uuid::randomHex(), 'product', null, $quantity))
            ->setPrice(new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()))
            ->setDeliveryInformation(
                new DeliveryInformation(
                    $quantity,
                    $weight,
                    $freeDelivery,
                    null,
                    null,
                    $height,
                    $width,
                    $length,
                )
            );
    }
}
->getMock();
        $costs = new CalculatedPrice(0.0, 0.0, new CalculatedTaxCollection()new TaxRuleCollection());
        $delivery->expects(static::atLeastOnce())->method('getShippingCosts')->willReturn($costs);
        $newCosts = null;
        $delivery->expects(static::once())->method('setShippingCosts')->willReturnCallback(function D$costsParameter) use (&$newCosts): void {
            /** @var CalculatedPrice $newCosts */
            $newCosts = $costsParameter;
        });

        $lineItem = new LineItem(Uuid::randomHex(), 'product');
        $lineItem->setDeliveryInformation(
            new DeliveryInformation(
                10,
                12.0,
                true,
                null,
                $this->deliveryTime
            )
        );
        $lineItem->setPrice(new CalculatedPrice(1, 1, new CalculatedTaxCollection()new TaxRuleCollection()));
        $price = $lineItem->getPrice();
        static::assertNotNull($price);

        
$deliveryProcessor = $this->getContainer()->get(DeliveryProcessor::class);

        $cartDataCollection = new CartDataCollection();
        $cartDataCollection->set(
            DeliveryProcessor::buildKey($this->salesChannelContext->getShippingMethod()->getId()),
            $this->salesChannelContext->getShippingMethod()
        );
        $originalCart = new Cart('original');
        $calculatedCart = new Cart('calculated');

        $lineItem = new LineItem('test', LineItem::PRODUCT_LINE_ITEM_TYPE);
        $lineItem->setDeliveryInformation(new DeliveryInformation(5, 0, false));
        $lineItem->setPrice(new CalculatedPrice(5.0, 5.0, new CalculatedTaxCollection([
            new CalculatedTax(5, 19, 5),
        ])new TaxRuleCollection()));

        $calculatedCart->setLineItems(new LineItemCollection([$lineItem]));

        $cartBehavior = new CartBehavior();

        static::assertCount(0, $calculatedCart->getDeliveries());

        $deliveryProcessor->process($cartDataCollection$originalCart$calculatedCart$this->salesChannelContext, $cartBehavior);

        
$toCalculate->add($lineItem);
        }
    }

    private function enrich(LineItem $lineItem): void
    {
        if ($lineItem->getDeliveryInformation() !== null) {
            return;
        }

        $lineItem->setDeliveryInformation(new DeliveryInformation($lineItem->getQuantity(), 0, false));
    }
}
 $configData['fields']);
    }

    private function createLineItem(int $stock, string $id = 'line-item-id'): LineItem
    {
        $lineItem = new LineItem(
            $id,
            LineItem::PRODUCT_LINE_ITEM_TYPE,
            'product-id'
        );

        $lineItem->setDeliveryInformation(new DeliveryInformation(
            $stock,
            1.0,
            false
        ));

        return $lineItem;
    }
}
$deliveryTime = null;
        if ($product->getDeliveryTime() !== null) {
            $deliveryTime = DeliveryTime::createFromEntity($product->getDeliveryTime());
        }

        $weight = $product->getWeight();

        $lineItem->setStates($product->getStates());

        if ($lineItem->hasState(State::IS_PHYSICAL)) {
            $lineItem->setDeliveryInformation(
                new DeliveryInformation(
                    (int) $product->getAvailableStock(),
                    $weight,
                    $product->getShippingFree() === true,
                    $product->getRestockTime(),
                    $deliveryTime,
                    $product->getHeight(),
                    $product->getWidth(),
                    $product->getLength()
                )
            );
        }

        
Home | Imprint | This part of the site doesn't use cookies.