Change Shipping method will throw out exception in Shopware6, although id exists in database

22 Views Asked by At

I will get error like this: enter image description here

..although this id exists in database of shopware6, as U can regard here: enter image description here

I will get this id through Dependendency Injection using this code:

  #[NoReturn] private function assignShippingObject(object $shippingObject, SalesChannelContext $context): void
{
    $shippingId = $shippingObject->getId();
    $contextToken = $context->getToken();
    $dataBag = new DataBag([
        'shippingMethodId' => $shippingId
    ]);
    $this->contextSwitcher->update($dataBag, $context);
}

I injected contextSwitcher in Constructor of class implementing Interface CartProcessorInterface. I will get Shipping object and id like this:

 $shippingMethods = $this->database->readTableShipping(Context::createDefaultContext());
    foreach ($shippingMethods as $key => $value) {
        $arShippingId[] = $key;
        $arShippingObj[] = $value;
    }

last but not least, here is my services.xml:

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
        <service id="WtShippingCalc\Core\Checkout\Cart\ShippingProcessor">
            <argument type="service" id="Shopware\Core\System\SalesChannel\SalesChannel\SalesChannelContextSwitcher"/>
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
            <argument type="service" id="WtShippingCalc\Service\ContactDatabaseShipping"/>
            <!-- after product collector/processor -->
            <tag name="shopware.cart.processor" priority="4500"/>
        </service>
        <service id="WtShippingCalc\Subscriber\ShippingCalc">
            <tag name="kernel.event_subscriber"/>
        </service>
        <!--Publishing pluginModule DatabaseConnection of table product to Shopware6-->
        <service id="WtShippingCalc\Service\ContactDatabaseShipping">
            <argument type="service" id="shipping_method.repository"/>
        </service>
    </services>
</container>

I absolutely don't understand, why I will get this exception as id is verifiably in database Can anybody tell me, why I can't change shipping method in shopware6? What is wrong with this code?

0

There are 0 best solutions below