0

I have tried the below link and some github links Shipping Address Missing on Payment Page Refresh

When i refresh the page in second step billing address gets empty only country will be visible. Anyone suggest what is causing for this, I dig out more with no success.

2 Answers 2

2

I fixed this issue by Enable the persistent shoppingcart. Stores -> Configuration -> Customers -> Persistent Shopping Cart -> Enable Persistence

Please override the magento/module-customer/view/frontend/web/js/customer-data.js

Comment this code:-

 /**
 * Invalidate Cache By Close Cookie Session
 */

invalidateCacheByCloseCookieSession = function () {
    if (!$.cookieStorage.isSet('mage-cache-sessid')) {
        $.cookieStorage.set('mage-cache-sessid', true);
        storage.removeAll();
    }
};

Add new code :-

 /**
 * Invalidate Cache By Close Cookie Session
 */

invalidateCacheByCloseCookieSession = function () {
    if (!$.mage.cookies.get('mage-cache-sessid')) {
        $.mage.cookies.set('mage-cache-sessid', true);
         storage.removeAll();
    }
};
0

I fixed this issue by disabling the persistent shoppingcart. Stores -> Configuration -> Customers -> Persistent Shopping Cart -> Enable Persistence

I found it by debugging this Observer: magento/module-persistent/Observer/CheckExpirePersistentQuoteObserver.php. This observer is triggered by controller_action_predispatch. In this file is are a few checks and if they pass they will expire the quote which will also remove mage-cache-sessid cookie. This results in triggering this function:

 /**
     * Invalidate Cache By Close Cookie Session
     */
    invalidateCacheByCloseCookieSession = function () {
        if (!$.cookieStorage.isSet('mage-cache-sessid')) {
            $.cookieStorage.set('mage-cache-sessid', true);
            storage.removeAll();
        }
    };

in the magento/module-customer/view/frontend/web/js/customer-data.js file. Here the storage.removeAll(); will empty the localstorage.

If you don't want to disable persistent shopping cart, you need take a look at the checks in the Observer: magento/module-persistent/Observer/CheckExpirePersistentQuoteObserver.php.

if ($this->_persistentData->isEnabled() &&
    !$this->_persistentSession->isPersistent() &&
    !$this->_customerSession->isLoggedIn() &&
    $this->_checkoutSession->getQuoteId() &&
    !$observer->getControllerAction() instanceof \Magento\Checkout\Controller\Onepage
    // persistent session does not expire on onepage checkout page to not spoil customer group id
    ) {
        $instance = $instance;
        $this->_eventManager->dispatch('persistent_session_expired');
        $this->quoteManager->expire();
        $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null);
    }

With !$observer->getControllerAction() instanceof \Magento\Checkout\Controller\Onepage they try to prevent to lose the checkout data. But in my case I use custom modules like: PostNL which had their own controller actions in the checkout, so this check would pass and the localstorage was cleared.

PS. There is allready an upcoming fix: https://github.com/magento/magento2/commit/bcffc4161e4960713922506870e1a4b711c5ca9e#diff-ee3a4dc8a625074b5313aa7d915944fd where the check is based on the requestUri. A side note is that if you leave the checkout page the localstorage is also cleared.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.