buildByUsingShippingMethod example

public function build(Cart $cart, CartDataCollection $data, SalesChannelContext $context, CartBehavior $cartBehavior): DeliveryCollection
    {
        $key = DeliveryProcessor::buildKey($context->getShippingMethod()->getId());

        if (!$data->has($key)) {
            throw ShippingException::shippingMethodNotFound($context->getShippingMethod()->getId());
        }

        /** @var ShippingMethodEntity $shippingMethod */
        $shippingMethod = $data->get($key);

        return $this->buildByUsingShippingMethod($cart$shippingMethod$context);
    }

    public function buildByUsingShippingMethod(Cart $cart, ShippingMethodEntity $shippingMethod, SalesChannelContext $context): DeliveryCollection
    {
        $delivery = $this->buildSingleDelivery($shippingMethod$cart->getLineItems()$context);

        if (!$delivery) {
            return new DeliveryCollection();
        }

        return new DeliveryCollection([$delivery]);
    }

    }

    /** * @dataProvider getLineItemsThatResultInAnEmptyDelivery */
    public function testLineItemResultInAnEmptyDelivery(LineItemCollection $lineItems): void
    {
        $cart = new Cart('cart-token');
        $cart->setLineItems($lineItems);

        $deliveries = (new DeliveryBuilder())->buildByUsingShippingMethod(
            $cart,
            new ShippingMethodEntity(),
            $this->createMock(SalesChannelContext::class),
        );

        static::assertEquals(0, $deliveries->count());
    }

    /** * @return iterable<array{0: LineItemCollection}> */
    
Home | Imprint | This part of the site doesn't use cookies.