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

Created on 30 Sep 2016  路  64Comments  路  Source: magento/magento2

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

Checkout Format is valid needs update bug report

Most helpful comment

Same also on 2.2.2. :(

All 64 comments

We're experiencing the exact same issue, hoping for a fix soon.

it seems Magento 2.1.1 has the same issue

+1 It was exists in previous versions (2.0.7, 2.1.0) but we were thinking it is a theme issue. Now using 2.1.1, checked everything, still exists.

There is an undefined bug with Magento 2.1.1. We also have the same issue. But there is no issue with old version (2.0). I think it is javascript issue.

@szreka this issue is fixed for develop branch now.

If there is, can you provide commit link.

Thanks

@SerhiyShkolyarenko how to fix it? Can you show me commit link?

Thanks

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

@szreka @jimmyhien @rbostan please let me know if that fixes helped you.

@SerhiyShkolyarenko Great! Thank you a lot. It works.

Corresponding backport issues to 2.1.x are MAGETWO-59024 and MAGETWO-59024.

@SerhiyShkolyarenko It worked for me with additions (branch 2.1, v 2.1.2)

define(
    [
        'jquery',
        'ko',
        './shipping-rates-validation-rules',
        '../model/address-converter',
        '../action/select-shipping-address',
        './postcode-validator',
        'mage/translate',
        'uiRegistry',
+ --->  'Magento_Checkout/js/model/quote'
    ],
    function (
        $,
        ko,
        shippingRatesValidationRules,
        addressConverter,
        selectShippingAddress,
        postcodeValidator,
        $t,
        uiRegistry,
+ --->  quote
    ) {

@SerhiyShkolyarenko can I get the link to MAGETWO-58730 - commit e788a24 ?

@Ctucker9233 it's not delivered here to develop branch. Sorry, i didn't check task status properly. Please, try to updated the code in 2-3 days, the fix has a good chance to be delivered soon.

Any update on this issue? I don't think it's in development branch yet.

MAGETWO-58730 - commit e788a24 is delivered to develop branch too.
@PieterCappelle is the issue reproducible for you on the clean Magento installation? Which configuration changes have you performed?

We are closing this issue because it hasn鈥檛 been updated in more than two weeks. If you can still reproduce this issue, please create a new GitHub issue report.

I don't think it is fixed... app/code/Magento/ doesn't exist in Magento 2.1x CE

@justinahsnyder I just checked it and the fix is in 2.1.4. Look under the vendor folder instead of the app folder.

I have very similar issue, but only the postcode is disappearing.

@SerhiyShkolyarenko is there a version of this fix compatible with EE 2.1.7?
All commits I see seem to be compatible only with 2.2

@SerhiyShkolyarenko @justinahsnyder @tkacheva @czettnersandor Guys any solution for magento 2.1.7 ?

I have the same issue on Magento 2.2.1. Any fixes?

I have the same issue on Magento 2.2.0.

@tonytrinh206 and @gemini9988 did you guys get any solution?

Im having the same issue on 2.2.2 also

Same also on 2.2.2. :(

@richardechidna I have installed a refresh Magento 2.1 and it fixed the problem

@tonytrinh206 thanks for the info :) However my issue is in 2.2.1 , with 2.1 I hadn't faced this issue!!!

Issue is still present on 2.2.3.

I have the same issue in Magento 2.2.2

After debugging this issue further I have found a scenario where this is still happening.
Version of magento 2.2.2

The checkout page is accessible on the {{base_dir}}/checkout and {{base_dir}}/checkout/

In vendor/magento/module-checkout/view/frontend/web/js/model/step-navigator.js:192

window.location = window.checkoutConfig.checkoutUrl + '#' + code;

The checkout url is forced to the {{base_dir}}/checkout/ with a #payment resulting in a refresh of the page.

@magento-engcom-team
In order to fix this issue the {{base_dir}}/checkout url should automatically redirect to {{base_dir}}/checkout/ in order to prevent javascript to issue a refresh.

@stormbyte that does not seem related. The issue still occurs even when starting the checkout at checkout/ instead of checkout.

@stormbyte yep, I have implemented that slash solution and result is the same.

Is it possible to implement something like here https://magento.stackexchange.com/a/82080 ?

@swayoleg that is concerning Magento 1.

Any workaround for m2 ?

@SerhiyShkolyarenko can we reopen it ?
at 2.2.3 (for me EE) it seems that we have same problem again.

Happening in 2.2.4 (CE).
I second a re-opening of the issue.

I guys, i'm facing out the same issue, in the shipping method, as guest, i get the wrong or incomplete data. The registered account works fine. If you try as guest to go to shipping from billing step and then save data to go next to shipping, data is not changed but you have older. But if you clear the cache and reload the page data submitted it's correct. Now i think the solution it's to clear the cache on each step or reload the page again. Reloading even without clearing the cache works but it's not a cute solution.

The culprit seems to be invalidateCacheByCloseCookieSession()
What's the reason behind this piece of code on line 31? Why would it be great to clear all storage data if the customer is not logged in? https://github.com/magento/magento2/commit/f066af00cd7bd5a169956c954dd2ba68f618176c

After some more digging, found that for some reason (I'm still trying to figure out why it exists) the mage-cache-sessid is always cleared if it exists.

https://github.com/magento/magento2/commit/65b146bbe3466ce5b5821a080ec4ac9f88ead213#diff-e480a40ebe714315b7ca494bf3c04ec9R44

@pedrosousa13 , this is not an issue what you see there. This is called only by event persistent_session_expired.

What issue I have found in one of our projects was the way how this cookie is set

 $.cookieStorage.set('mage-cache-sessid', true);

I got it to work with mage/cookies

You can give a try if this alternative works better also for you


--- view/frontend/web/js/customer-data-o.js 2018-05-31 14:10:14.392520656 +0200
+++ view/frontend/web/js/customer-data.js   2018-05-31 14:16:24.618722182 +0200
@@ -12,7 +12,8 @@
     'ko',
     'Magento_Customer/js/section-config',
     'mage/storage',
-    'jquery/jquery-storageapi'
+    'jquery/jquery-storageapi',
+    'mage/cookies'
 ], function ($, _, ko, sectionConfig) {
     'use strict';

@@ -50,8 +51,13 @@
      * Invalidate Cache By Close Cookie Session
      */
     invalidateCacheByCloseCookieSession = function () {
-        if (!$.cookieStorage.isSet('mage-cache-sessid')) {
-            $.cookieStorage.set('mage-cache-sessid', true);
+        // PATCH: ER> for some reason using 'cookieStorage' is loosing info.
+        // if (!$.cookieStorage.isSet('mage-cache-sessid')) {
+        //     $.cookieStorage.set('mage-cache-sessid', true);
+        //     storage.removeAll();
+        // }
+        if (!$.mage.cookies.get('mage-cache-sessid')) {
+            $.mage.cookies.set('mage-cache-sessid', true);
             storage.removeAll();
         }
     };

Issue is present in Magento 2.2.2 EE.

I tested your patch @elvinristi (thanks for sharing), but it didn't solve the problem unfortunately.

@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);
             }

Hi @elvinristi where can we find that file ??

@fk-whothat

if using this github for code then

if using composer then

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

It did not work :/

might be that conditions for you are different or it was using in cache old logic. Would be great if someone extra with similar issue could also confirm it.

I have tried to debug a little bit and can see that when the getData function is running the Data value entries is empty on refreshing the page, so the problem should be laying before the getData function

@elvinristi your patch works for me. Thanks!

@elvinristi thank you I got it to work after using your patch for both customer-data.js and checkout-data.js

hi lennartbee, can you tell me in which section you added pach in customer-data.js file? i have added only in checkout-data.js and it is not working for me. if you could tell where to add in customer-data.js . I will add and check it

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.

Hi @lennartbee,

I'm curious to see your changes to Magento_Customer/js/customer-data.js - would you be able to share? 馃檹

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-checkoutviewfrontendwebjscheckout-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.

@loganstellway & @sanderjongsma please be aware that https://github.com/magento/magento2/commit/bcffc4161e4960713922506870e1a4b711c5ca9e#diff-ee3a4dc8a625074b5313aa7d915944fd can throw errors if $refererUri on line 138 is null (if there is no refferer). I added "!is_null($refererUri) &&" before "false !== strpos($refererUri, $this->checkoutPagePath)" to prevent that.

We were not able to reproduce this issue. Can anyone provide updated Steps to Reproduce?
1

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

I have the same issue using version 2.2.5 EE

Issue is still persisting on our installation on version 2.2.2 CE. Just like the comments above, the address reverts to default region + default country after refreshing the page.

Are there any solutions yet to this issue?

Edit:

After analyzing the above tickets, especially @elvinristi 's, I've also found that the issue lies withing the checkout-data.js.

You can update/add a new checkout-data.js to <Vendor>/<Theme>/Magento_Checkout/web/js/checkout-data.js after you've copied the original from the vendor folder.

/**
 * Copyright 漏 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * Checkout adapter for customer data storage
 *
 * @api
 */
define([
    'jquery',
    'Magento_Customer/js/customer-data',
    'jquery/jquery-storageapi'
], function ($, storage) {
    'use strict';

    var cacheKey = 'checkout-data',

        /**
         * @param {Object} data
         */
        saveData = function (data) {
            storage.set(cacheKey, data);
        },

        /**
         * @return {*}
         */
        getData = function () {
            var data = storage.get(cacheKey)();

            if ($.isEmptyObject(data)) {
                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
                        'newCustomerShippingAddress': null, //Shipping address pulled from persistence storage for customer
                        'selectedShippingRate': null, //Shipping rate pulled from persistence storage
                        'selectedPaymentMethod': null, //Payment method pulled from persistence storage
                        'selectedBillingAddress': null, //Selected billing address pulled from persistence storage
                        'billingAddressFromData': null, //Billing address pulled from persistence storage
                        'newCustomerBillingAddress': null //Billing address pulled from persistence storage for new customer
                    };
                }
                saveData(data);
            }

            return data;
        };
****

Seems to be fixed in 2.2.6

Is there any fixes for 2.1.9

Was this page helpful?
0 / 5 - 0 ratings