magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

Local storage is cleaned if persistent shopping cart is enabled #13690

Closed alexber88 closed 4 years ago

alexber88 commented 6 years ago

Preconditions

  1. Magento CE 2.2.2 with Sample Data
  2. PHP 7.0
  3. Guest checkout enabled
  4. Persistent shopping cart is enabled

Steps to reproduce

  1. Add product to cart.
  2. Go to checkout page
  3. Select shipping method
  4. Reload page
  5. Go to cart page

Expected result

  1. Shipping method should be preselected on checkout after page reload
  2. Shipping costs should be calculated on cart page
  3. Local storage shouldn't be cleaned while page reloading

Actual result

  1. Shipping method is not preselected on checkout page after reloading page
  2. Shipping costs are not calculated on the cart page
  3. Local storage is cleaned while page reloading

Additional information

  1. Detailed steps to reproduce were provided in the comment https://github.com/magento/magento2/issues/13690#issuecomment-429316214
magento-engcom-team commented 6 years ago

@alexber88, thank you for your report. We've acknowledged the issue and added to our backlog.

btwq commented 6 years ago

Working on it #MLAU18

btwq commented 6 years ago

Not able to reproduce on 2.2.2

@alexber88 are you loading your cart on the same HTTP / HTTPS socket as when you checked out? In my case, checkout is on HTTPS and when loading cart on HTTPS, the selecting shipping method and totals are showing correctly.

alexber88 commented 6 years ago

@btwq i'm using http.

magefan commented 6 years ago

The same issue on Magento 2.2.2 and 2.2.3

To quickly reproduce the issue you need to

  1. Be as a guest (not logged into an account)
  2. Go to the checkout page
  3. Enter for e.g. first name and last name
  4. Refresh the page

Expected result: You see entered first name and last name

Actual result: All fields are blank

We have done a digging into the code, so

  1. In Magento\Persistent\Observer\RefreshCustomerData::execute persistent extension clean the "mage-cache-sessid" cookie key.

  2. This observer is called in another observer \Magento\Persistent\Observer\CheckExpirePersistentQuoteObserver::execute and the term

    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
        ) {

    is always TRUE if persistent shopping cart is enabled and you visit the website as a guest, so the "mage-cache-sessid" cookie key is always removed.

  3. When the mage-cache-sessid is missing or is empty Magento remove all local storage data. Please see vendor/magento/module-customer/view/frontend/web/js/customer-data.js

    invalidateCacheByCloseCookieSession = function () {
        if (!$.cookieStorage.isSet('mage-cache-sessid')) {
            $.cookieStorage.set('mage-cache-sessid', true);
            storage.removeAll();
        }
    };
  4. $this->_persistentSession->isPersistent() term return false when you is a guest beckouse \Magento\Persistent\Model\Session::setPersistentCookie never called for guest. It anly called for customer in vendor/magento/module-persistent/Observer/SynchronizePersistentOnLoginObserver.php

and

\Magento\Persistent\Model\Session::renewPersistentCookie is also called only for customer in vendor/magento/module-persistent/Observer/RenewCookieObserver.php

therouv commented 6 years ago

mhlej18

therouv commented 6 years ago

@magento-engcom-team give me 2.2-develop instance

magento-engcom-team commented 6 years ago

Hi @therouv. Thank you for your request. I'm working on Magento 2.2-develop instance for you

magento-engcom-team commented 6 years ago

Hi @therouv, here is your Magento instance. Admin access: https://i-13690-2-2-develop.engcom.dev.magento.com/admin Login: admin Password: 123123q Instance will be terminated in up to 3 hours.

therouv commented 6 years ago

I can't reproduce this issue on a vanilla 2.2-develop instance with the described steps. Seems to be fixed in the latest version.

I enabled guest checkout and persistent shopping cart in store configuration: 13690_conf1 13690_conf2

I added a category and product and then added the product to the cart. After I visited the checkout for the first time the values are empty (which is correct since I'm not logged in):

13690_screen1

I then entered a firstname and lastname and hit the refresh button of my browser multiple times. After every time when the page rendered, the entered values were still present in the firstname and lastname field.

13690_screen2

See recorded screencast of the followed steps here

enl commented 6 years ago

Oh, it was tricky! I am still able to reproduce it on vanilla.

Server details

php --version
PHP 7.0.32-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Oct  1 2018 11:45:35) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.32-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
    with blackfire v1.18.0~linux-x64-non_zts70, https://blackfire.io, by SensioLabs

Preconditions

First,

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
bin/magento setup:install
bin/magento sampledata:deploy

So that it is the latest and the most vanilla magento I can imagine:

bin/magento --version
Magento CLI version 2.2.6
  1. Enable persistent shopping cart
  2. Allow guest checkout
  3. Enable any credit cart payment method (I enabled Braintree Credit Card)

configuration___settings___stores___magento_admin

Additional information

In order to fail transaction you need to use the following payment data: Credit card: 4000111111111115 Expires at: any date in future CVC: 123 Transaction amount: >2000.0 <3000 (transaction status depends on amount, we need failure in order to reproduce the bug)

See https://developers.braintreepayments.com/guides/credit-cards/testing-go-live/php

Steps to reproduce

  1. Add some products to cart to get total between $2000 and $3000, see additional information section
  2. Proceed to checkout
  3. Add your shipping address
  4. Select Credit card payment method
  5. Fill in fake credit card data to make it fail (see additional information section)
  6. Press "Place order"
  7. Refresh the page

Expected results

Shipping address information is still on place

Actual results

checkout

mark-gene commented 6 years ago

I am also seeing this error on 2.2.6. I could see the issue once I had something in my basket and was not logged in. I could then see the XHR Network requests in the browser calling ?sections=directory-data&... ?sections=cart&... even though these were already in local storage.

After going through some code I can see the same thing as @magefan in that the backend code Magento\Persistent\Observer\execute() is deleting the cookie "mage-cache-sessid"

Then the frontend module-customer/view/frontend/web/js/customer-data.js is checking if that cookie is NOT set and then resets the cookie and removes everything from local storage.

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

The backend will then clear this cookie again causing the FE to reset and clear storage - and so forth.

This issue only happens when persistent mode is enabled.

The backend observer gets from "persistent_session_expired" which is dispatched from Magento\Persistent\Observer\CheckExpirePersistentQuoteObserver and checks

Hope this helps.

kpitn commented 5 years ago

I can confirm this is still in Magento 2.3.0 I don't understand the goal to force refresh "sections xhr call", this is a major performance issue. Not logged visitors keep "call xhr sections" on every page on the store, sometimes 3 calls per page.

sections

Is the solution to disable "RefreshCustomerData" Observer ?

onepack commented 5 years ago

I have noticed the same bug in M2.3 with PHP7.2. I was logged in as a client in a demo environment in two browsers at the same time. After I returned from a lunch I refreshed the page and in firefox an empty collection was returned on all pages. So I went to the same account in Internet Explorer and there on the same account the collections became empty as well after a refresh. (FPC on a customer group?) On a second testing account that is using a different customer group in Google Chrome the collections remained the same (not empty). I noticed this was occurring after I enabled the persistent shopping cart and stopped after I disabled it again.

lisovyievhenii commented 5 years ago

We faced with the same problem.

It is already fixed in 2.3: https://github.com/magento/magento2/blob/2.3.0/app/code/Magento/Persistent/Observer/CheckExpirePersistentQuoteObserver.php

BUT if you, as guest user, go to checkout, fill in the shipping data. Than you decided to buy another product and you go to some PDP, return back to checkout and your address becomes empty.

chris-huffman commented 5 years ago

I'm seeing the same issue, it seemed much easier to reproduce on Magento Commerce version. Seems like the easy solution is to disable "RefreshCustomerData"observer as @kpitn mentions. But the original commit message "My Wishlist control contains incorrect info after longterm session is over" doesn't give much insight into the original reason why this observer was added. I don't like just removing things, but I'd rather have the postcode/selected shipping method be correct than some hard-to-reproduce wishlist issue.

goutamfulcrum commented 5 years ago

I have upgraded the magento version from 2.2.5 to 2.2.8 and in 2.2.5 persistent shopping cart was disable so in 2.2.5 my custom code of storing some dynamic data(data source was some url) in LocalStorage with help of sections.xml was working good but it is not working with 2.2.8 but in 2.2.8 it works with logged-in user.

What can be the possible solution.

m2-assistant[bot] commented 4 years ago

Hi @engcom-Echo. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


m2-assistant[bot] commented 4 years ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 4 years ago

Hello @alexber88 We have rechecked this issue on Magento 2.4-develop, and it seems to be fixed. Please see the attachment below. We Enable Persistence and try to reproduce this by refreshing the Shipping page and adding one more Product ti the Cart shoping_cart

As for the comment https://github.com/magento/magento2/issues/13690#issuecomment-429316214 This is also not reproducible. We have configured the Braintree and tried to reproduce with the described steps. The Shipping info didn't disappear place_order

We are closing this issue. If you still experience the same problem on Magento 2.4-develop, please feel free to comment, reopen or create new ticket according to the Issue reporting guidelines . Thank you for collaboration.

roni-sooryen commented 4 years ago

Related tickets: https://github.com/magento/magento2/issues/6817 https://github.com/magento/magento2/issues/16149 https://github.com/magento/magento2/issues/5959 https://github.com/magento/magento2/issues/13690 https://github.com/magento/magento2/issues/22112