Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alexber88 opened this issue Feb 16, 2018 · 21 comments
Closed

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

alexber88 opened this issue Feb 16, 2018 · 21 comments
Assignees
Labels
Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@alexber88
Copy link

alexber88 commented Feb 16, 2018

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 Local storage is cleaned if persistent shopping cart is enabled #13690 (comment)
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Feb 16, 2018
@magento-engcom-team
Copy link
Contributor

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

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Feb 19, 2018
@btwq
Copy link

btwq commented Feb 21, 2018

Working on it #MLAU18

@btwq
Copy link

btwq commented Feb 21, 2018

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.

@btwq btwq self-assigned this Feb 21, 2018
@alexber88
Copy link
Author

@btwq i'm using http.

@magefan
Copy link
Contributor

magefan commented Jun 8, 2018

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.

  1. 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();
        }
    };
  1. $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 therouv self-assigned this Jun 17, 2018
@therouv
Copy link
Contributor

therouv commented Jun 17, 2018

#mhlej18

@therouv
Copy link
Contributor

therouv commented Jun 17, 2018

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

@magento-engcom-team
Copy link
Contributor

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

@magento-engcom-team
Copy link
Contributor

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
Copy link
Contributor

therouv commented Jun 17, 2018

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

@therouv therouv closed this as completed Jun 17, 2018
@enl
Copy link
Contributor

enl commented Oct 12, 2018

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

@enl enl reopened this Oct 12, 2018
@mark-gene
Copy link

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

  • If persistence is enabled
  • If customer is not logged in
  • If checkout session has a quoteId
  • If the current request is NOT from the checkout

Hope this helps.

@kpitn
Copy link

kpitn commented Dec 8, 2018

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
Copy link

onepack commented Dec 11, 2018

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
Copy link
Contributor

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
Copy link

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
Copy link

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.

@engcom-Echo engcom-Echo self-assigned this Jan 2, 2020
@m2-assistant
Copy link

m2-assistant bot commented Jan 2, 2020

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:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@engcom-Echo engcom-Echo removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Jan 2, 2020
@engcom-Echo engcom-Echo removed their assignment Jan 2, 2020
@engcom-Bravo engcom-Bravo self-assigned this Jan 10, 2020
@m2-assistant
Copy link

m2-assistant bot commented Jan 10, 2020

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Bravo
Copy link
Contributor

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 #13690 (comment)
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
Copy link

roni-sooryen commented Feb 3, 2020

Related tickets:
#6817
#16149
#5959
#13690
#22112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests