magento2: Billing address information goes missing after refreshing Payment page on checkout

Preconditions

Magento 2.1.0

Steps to reproduce

  1. Go to checkout after adding a product to basket.
  2. Fill in the form and go to Payment page.
  3. Refresh the page.
  4. In the Payment Method selected uncheck the My billing and shipping address are the same.
  5. Check it back again.

Expected result

The Shipping and Billing Address will be the exactly same both on checkout and the basket.

Actual result

Apart from the Postal Code and Country every other information disappears.

Before Refresh:

screen shot 2016-09-30 at 11 39 14

After Refresh:

screen shot 2016-09-30 at 11 36 57

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 18
  • Comments: 67 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Seems to be fixed in 2.2.6

Same also on 2.2.2. 😦

There were several related bugs fixed. Please look at MAGETWO-58730 - commit e788a24. Github issue #6564 MAGETWO-58062 - commit f890acfa

Issue is still present on 2.2.3.

We are closing this issue due to inactivity. If anyone wants to update it, please reopen the issue.

@ebaschiera, have also second patch for Magento_Checkout in place which fixes an issue for me when I enter address in checkout, go to the payment tab and reload then page.


--- view/frontend/web/js/checkout-data.js.org
+++ view/frontend/web/js/checkout-data.js
@@ -10,7 +10,8 @@
  */
 define([
     'jquery',
-    'Magento_Customer/js/customer-data'
+    'Magento_Customer/js/customer-data',
+    'jquery/jquery-storageapi'
 ], function ($, storage) {
     'use strict';
 
@@ -30,6 +31,9 @@
             var data = storage.get(cacheKey)();
 
             if ($.isEmptyObject(data)) {
+                //PATCH if data in localStorage still, use it.
+                data = $.initNamespaceStorage('mage-cache-storage').localStorage.get(cacheKey);
+                if ($.isEmptyObject(data)) {
                 data = {
                     'selectedShippingAddress': null, //Selected shipping address pulled from persistence storage
                     'shippingAddressFromData': null, //Shipping address pulled from persistence storage
@@ -40,6 +44,9 @@
                     'billingAddressFromData': null, //Billing address pulled from persistence storage
                     'newCustomerBillingAddress': null //Billing address pulled from persistence storage for new customer
                 };
+                }
+                //PATCH
+
                 saveData(data);
             }
 

I have the same issue using version 2.2.5 EE

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.

@elvinristi your patch works for me. Thanks!

I have the same issue in Magento 2.2.2

hi @loganstellway Ultimately I got it working on 2.2.5 perfectly with a combination of https://github.com/magento/magento2/commit/bcffc4161e4960713922506870e1a4b711c5ca9e#diff-ee3a4dc8a625074b5313aa7d915944fd as mentioned by @sanderjongsma and module-checkout\view\frontend\web\js\checkout-data.js as mentioned by @elvinristi. I use the original customer-data.js now on 2.2.5. Also, I disabled Redis for the sessions while testing and left that disabled for now.

So I suggest you test editing @elvinristi solution on checkout-data.js first in combination with https://github.com/magento/magento2/commit/bcffc4161e4960713922506870e1a4b711c5ca9e#diff-ee3a4dc8a625074b5313aa7d915944fd as mentioned by @sanderjongsma with Redis for session-caching turned off. Our full page cache is on Varnish, but our test environment is not and it doesn’t make a difference.

@fk-whothat

if using this github for code then

if using composer then

  • vendor/magento/module-checkout/view/frontend/web/js/checkout-data.js