getOldShippingMethodName example

/** * Remove all PaymentMethodChangedErrors and ShippingMethodChangedErrors from cart */
    private function removeSwitchNotices(ErrorCollection $cartErrors): void
    {
        foreach ($cartErrors as $error) {
            if (!$error instanceof ShippingMethodChangedError && !$error instanceof PaymentMethodChangedError) {
                continue;
            }

            if ($error instanceof ShippingMethodChangedError) {
                $cartErrors->add(new ShippingMethodBlockedError($error->getOldShippingMethodName()));
            }

            if ($error instanceof PaymentMethodChangedError) {
                $cartErrors->add(new PaymentMethodBlockedError($error->getOldPaymentMethodName()));
            }

            $cartErrors->remove($error->getId());
        }
    }
}
Error $error,
        KernelBrowser $browser,
        string $salesChannelId,
        string $productId,
        bool $shouldSwitchToDefault
    ): void {
        $availabilityRuleId = $this->createAvailabilityRule($salesChannelId);
        $salesChannelRepository = $this->getContainer()->get('sales_channel.repository');

        if ($error instanceof ShippingMethodChangedError) {
            $shippingMethodRepository = $this->getContainer()->get('shipping_method.repository');
            $blockedId = $this->getShippingMethodIdByName($error->getOldShippingMethodName());
            $newId = $this->getShippingMethodIdByName($error->getNewShippingMethodName());

            $shippingMethodRepository->update([
                [
                    'id' => $blockedId,
                    'availabilityRuleId' => $availabilityRuleId,
                ],
            ], Context::createDefaultContext());

            $salesChannelRepository->update([
                [
                    


    public function isPersistent(): bool
    {
        return true;
    }

    public function getParameters(): array
    {
        return [
            'newShippingMethodName' => $this->getNewShippingMethodName(),
            'oldShippingMethodName' => $this->getOldShippingMethodName(),
        ];
    }

    public function blockOrder(): bool
    {
        return false;
    }

    public function getId(): string
    {
        return sprintf('%s-%s-%s', self::KEY, $this->oldShippingMethodName, $this->newShippingMethodName);
    }
Home | Imprint | This part of the site doesn't use cookies.