1

TLDR

How can we reset or refresh or reload the quote session/cache key with the shipping address collection that belongs to it in Magento 2 checkout page.

Lengthy/Confusing Explanation

We are developing a custom checkout page with Mageplaza Onestepcheckout - the extension itself works ok without any extra functionality.

With this we are adding Address selector/choose as modal box with new address form - so here when ever customer submits a address its getting added to customer_address_entity as we have it in the code for new address.

With below code we are able to get the shipping methods works ok since magento finds matching address if the address was added/exist before.

    .............
    $quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode);
    $this->validateQuote($quote);
    $quote->setIsMultiShipping(false);

    try {
        $this->quoteRepository->save($quote);
    } catch (\Exception $e) {
        $this->logger->critical($e);
        throw new InputException(__('We are having a problem getting shipping rates. Please check the address you entered or contact customer service.'));
    }
    ..............

But if we use the newly added address from the our custom form in checkout to quote_object as Shipping address in this line $this->quoteRepository->save($quote); it throws exception as "Invalid customer address id [Last_added_customer_address_id]" - but this customer_address_id does exist in DB.

Because quote save goes into this callstack for to validate address against the current quote here \Magento\Quote\Model\QuoteAddressValidator::validate - this function always pulls only previous set of addresses - some how we have to say magento to reset the cache key/refresh the quote session/object to reload shipping address list but am not able to follow where/how that can be done.

This seems to be session/cache issue because if we add one more address then the previously added address pulls shipping methods ok since Magento refreshes the address list/quote shipping object some where - not sure how this is being done.

How can we reset or refresh or reload the quote session/cache key with the shipping address collection that belongs to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.