Magento2: [2.1.11] Add to cart, try to checkout, cart is empty but mini-cart has items.

Created on 30 Jan 2018  路  16Comments  路  Source: magento/magento2

Issue

We have been getting reports from users saying that they added product to cart, tried to checkout, but when they go to the cart, the cart was empty, but the mini-cart still showed products.

We have been getting customer complaints about this issue in every release of Magento 2 we have used since October, up to and including our current implementation which is 2.1.11.

This has obviously been a nightmare to debug, but we have figured out how to reproduce it 100%, in Luma.

Preconditions

Dedicated server,
Magento 2.1.11.
CentOS 7.3.
PHP 7.
MariaDB.
Double Redis (session and cache).
Images on a CDN.

Steps to reproduce

  1. Add product to cart
  2. Click on cart
  3. Click on checkout button multiple times before the checkout page has loaded. At least two clicks are necessary.
  4. You will now be on a cart page page that says your cart is empty but your minicart will still have content.

Actual result

The user will be directed to a cart page saying there are no items in the cart, but the mini-cart will still have contents.

Expected result

The cart should have items in it.

Misc

I believe that this is probably related to the "Hit refresh multiple times fast in checkout and your cart will be empty" bug edit which can be referenced here - https://github.com/magento/magento2/issues/12362

Fix

We added some client-side code to disable the "checkout" button after it was clicked, which solves this issue. This obviously does not resolve the fundamental problem (double refresh on checkout page clears cart) but it should be done anyway if for no other reason than to reduce server load. We can create a pull request for this if needed.

screen shot 2018-01-25 at 9 56 10 pm

Fixed in 2.2.x Fixed in 2.3.x Confirmed Format is valid Ready for Work Reproduced on 2.1.x

Most helpful comment

I'm on 2.2.6 and I can still replicate the issue.

All 16 comments

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

I can reproduce this in Magento 2.2 too.
see video record https://monosnap.com/file/3nG4CTflRD4qD6QusZAeskxRKzybEj

We are having the same issues on 2.1.11 Commerce with Redis for session storage.

Try to disable the FPC cache i have the same issue i think the checkout page has been cached when it was empty

What is the status on this issue? We see it also and it is a huge issue for an ecommerce platform.

We are on 2.1.12 with composer so we temporarily (till we will find an official fix for 2.1.x) replaced MagentoFrameworkSessionSessionManager of Magento 2.1.10 https://github.com/magento/magento2/blob/2.1.10/lib/internal/Magento/Framework/Session/SessionManager.php which hasn't such issues by placing it one folder Lib/Framework/Session of our module.
We did the override in the main composer.json of the project inside the "autoload" node:

"psr-4": {
      "Magento\\Framework\\Session\\": "vendor/yourvendor/yourmodule/Lib/Framework/Session"
    }
"exclude-from-classmap": [
      "vendor/magento/framework/Session/SessionManager.php"
    ],

That is solving for now.

Otherwise a simpler fix without composer can be by placing the same SessionManager of 2.1.10 in your own lib/internal/Magento/Session folder

@elioermini For what it's worth, I did not have luck with reverting the core code. I believe it is related to using PHP 7 - the fix I eventually was successful with is here: https://github.com/magento/magento2/issues/12362#issuecomment-346301084

Looking at the 2.2.3-develop branch, it seems that the Magento team is trying out the reverting solution as well, but I don't think that is going to be the solution here.

As someone pointed out in the linked thread, it would be nice to know specifically what risk Magento is trying to mitigate with the regenerate_session_id() call when going to checkout, as it is tempting to just remove that line altogether.

@allisonlawrencels Thanks for linking that other issue, that was a very interesting read. We are experiencing the exact same thing described in that thread - if you go to checkout, hit refresh a few times quickly and then the cart is empty.

I'll take a look at the solution that acetronaut posted and see if we can get that working here, we are currently on 2.1.12.

@allisonlawrencels exactly see my comment in #12362 we found out as well after a while the same fix you referenced but I forgot to amend it here. It is also solving this issue #4301 the only change in addition to #12362#issuecomment-373318974 I added in start() is $this->renewCookie($sid); after $this->validator->validate($this);

@aeu This issue duplicates https://github.com/magento/magento2/issues/12362
Closing. Please continue further tracking and discussion in mentioned ticket.
Thank you.

Hi @aeu. Thank you for your report.
The issue has been fixed in magento/magento2#14428 by @adrian-martinez-interactiv4 in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

Hi @aeu. Thank you for your report.
The issue has been fixed in magento/magento2#14429 by @adrian-martinez-interactiv4 in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

I see that this is fixed in 2.3.x and 2.2.x, is there any chance of a fix in the next 2.1.x update as well?

same issue on 2.1.12, cart is empty.
It happens when people clicked twice on the checkout button and the cart is empty but mini cart has items.

I'm on 2.2.6 and I can still replicate the issue.

Replicated on 2.2.4

Was this page helpful?
0 / 5 - 0 ratings