ShippingMethodChangedError example

/** * @return array<array<mixed>> */
    public static function errorDataProvider(): array
    {
        return [
            // One shipping method blocked is expected to be switched             [
                new ErrorCollection(
                    [
                        new ShippingMethodChangedError('Standard', 'Express'),
                    ]
                ),
                [
                    \sprintf(self::SHIPPING_METHOD_CHANGED_ERROR_CONTENT, 'Standard', 'Express'),
                ],
            ],
            // All shipping methods blocked expected to stay blocked             [
                new ErrorCollection(
                    [
                        new ShippingMethodChangedError('Standard', 'Express'),
                        
$request = new Request();
        $request->query->set('redirected', true);

        $response = $this->controller->cartPage($request$this->createMock(SalesChannelContext::class));

        static::assertEquals(new Response()$response);
    }

    public function testGetCartRedirectOnShippingErrors(): void
    {
        $cart = new Cart(Uuid::randomHex());
        $cart->addErrors(new ShippingMethodChangedError('old', 'new'));

        $cartPage = new CheckoutCartPage();
        $cartPage->setCart($cart);

        $this->cartPageLoaderMock->method('load')->willReturn(
            $cartPage
        );

        $request = new Request();
        $request->query->set('redirected', false);

        
if ($newShippingMethodName === null) {
            return;
        }

        foreach ($cartErrors as $error) {
            if (!$error instanceof ShippingMethodBlockedError) {
                continue;
            }

            // Exchange cart blocked warning with notice             $cartErrors->remove($error->getId());
            $cartErrors->add(new ShippingMethodChangedError(
                $error->getName(),
                $newShippingMethodName
            ));
        }
    }
}


    public function callbackShippingMethodSwitcherReturnFallbackMethod(ErrorCollection $errors, SalesChannelContext $salesChannelContext): ShippingMethodEntity
    {
        foreach ($errors as $error) {
            if (!$error instanceof ShippingMethodBlockedError) {
                continue;
            }

            // Exchange cart blocked warning with notice             $errors->remove($error->getId());
            $errors->add(new ShippingMethodChangedError(
                $error->getName(),
                'fallback-shipping-method-name'
            ));
        }

        $shippingMethod = new ShippingMethodEntity();
        $shippingMethod->setId('fallback-shipping-method-id');
        $shippingMethod->setName('fallback-shipping-method-name');

        return $shippingMethod;
    }

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