magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Cart caching problems

Open ivanweiler opened this issue 9 years ago • 48 comments

Description (*)

Hello,

If customer adds product to cart, content of its cart is cached in browsers local storage. Now, if price of any product in cart change for any reason (catalog rule, special price, main price change) while customer is on site:

  1. wrong price is displayed in mini cart on all pages
  2. wrong price is displayed in main Cart page, but right Summary box is reloaded with correct price; so there are 2 totally different prices displayed on Cart page for the same product (this one on current develop branch, not sure for stables)
  3. wrong price is even displayed on first Checkout step in Order Summary box

Any customer would be really confused with this, he/she would either quit or not notice change and buy at the wrong price.

This is just one example, I believe many more edge cases can be presented, maybe going out of stock or something like that.

I'm not sure if current customer data js cache has any mechanism to be invalidated by the server. Magento cache was flushed btw, has nothing to do with this.

It's also for discussion how secure is caching customer name and similar data to local storage, but that's another topic :)

Regards, Ivan

Preconditions (*)

Magento 2.4-develop

Steps to reproduce (*)

  1. From Magento Admin go to Catalog - Products, Add a Simple Product
  2. Fill in all the required fields, set Price 100 for example, Save the Product
  3. Open Store View, and Add the previously created Product to Cart
  4. From Magento Admin go to Catalog - Products, and Edit the previously created product, set Price to 90, for example. Save
  5. Open Store View, refresh the web page
  6. Click on Cart in the top right corner and verify the Price

Expected result (*)

The price should be updated to 90

Actual result (*)

The price in Cart remains 100 but the price of the Product in Category is updated to 90 price

Additional Notes (*)

The price is Updated in View and Edit Cart, and in Summary

ivanweiler avatar Mar 02 '16 23:03 ivanweiler

@ivanweiler Thank you for reporting. Indeed, this issue exists and we already have the task in our backlog (internal ticket MAGETWO-43095 containing multiple issues) to implement mechanism which would enable browser cache invalidation by the server. There are some more cases caused by this problem: #2339, #3280 We are going to update all the tickets as soon as issue is resolved.

If you have any concerns regarding customer data caching in the local storage please let us know, we are open to discussion. Thank you.

ishakhsuvarov avatar Mar 03 '16 13:03 ishakhsuvarov

Good to hear it's being worked on, thx.

ivanweiler avatar Mar 04 '16 11:03 ivanweiler

I'm experiences same bug, is there a date for solution? Thanks

JDavidVR avatar May 11 '16 21:05 JDavidVR

Looks like ( MAGETWO-43095 ) is the internal story where this would actually be solved

choukalos avatar May 11 '16 21:05 choukalos

same problem here with magento 2.0.7 version.

3 month now... it is great that magento internals create internal tickets but is there any timeline we user can see for the tickets? I see many cases where internal tickets where created month ago and are not solved till today. For us users it would be great just to know if magento works on the tickets and when can we expect solutions. For now internal ticket created means just ok it is documented but we have no info if this will be solved in days, weeks moth or years...

andidhouse avatar Jun 08 '16 19:06 andidhouse

Facing the issue of no customer name in top link because of local storage. Please fix this asap.

dimple-vasoya avatar Jun 09 '16 14:06 dimple-vasoya

Increased priority of the issue.

piotrekkaminski avatar Jun 20 '16 22:06 piotrekkaminski

I updated to 2.0.7, still having problems with this issue

JDavidVR avatar Jun 21 '16 20:06 JDavidVR

Can't the localStorage be updated regularly by polling the server? Would solve all the problems I think.

PascalBrouwers avatar Jun 27 '16 09:06 PascalBrouwers

I am using Magento 2.1.0 and facing similar issue. Is there any method that I can try ?

routbiplab avatar Aug 09 '16 07:08 routbiplab

I am also struggling with same issue. Awaiting FIX :(

kumarA8 avatar Nov 16 '16 12:11 kumarA8

@routbiplab @wclabhinav totally agree - no idea how you can online with this...

andidhouse avatar Nov 16 '16 12:11 andidhouse

v2.1.2 also too

LifeAsBook avatar Nov 22 '16 07:11 LifeAsBook

same issues here :(

webkulabhi avatar Dec 09 '16 09:12 webkulabhi

Is there any solution till ?

shahankitb997 avatar Mar 29 '17 03:03 shahankitb997

Hi @shahankitb997 Currently the issue is still not fixed. We will update the ticket as soon as we have anything to add. Thanks.

ishakhsuvarov avatar Mar 29 '17 07:03 ishakhsuvarov

it is now one year later since the ticket had been created @shahankitb997 - wow no solution so far!

andidhouse avatar Mar 29 '17 07:03 andidhouse

Well, to be fair, it doesn't seem like something you could fix with one line of code. The whole idea of caching to the local storage (which is: the information in local storage isn't changed until the next POST request because user didn't do any changes) may be misused here. I'm not saying real-time updates are needed here(if it is so, why even bother caching this stuff?), but there should be a way for the server to tell clients the localStorage-cached information was invalidated: maybe, a timestamp of when prices / promotion rules were last changed with each GET response.

korostii avatar Mar 29 '17 08:03 korostii

Issue is reported on Mar 3, 2016. Still no Solution? More than a year and crucial Issue. Not even work around released. Is there any specific date when it's going to fix or in which release we get this FIXED?

shahankitb997 avatar Mar 30 '17 09:03 shahankitb997

@shahankitb997 Currently there is no specific date for the fix to be delivered, however, based on community feedback, we are looking into ways to increase its priority. I will update this ticket as soon as more information will be available.

Thank you.

ishakhsuvarov avatar Mar 30 '17 12:03 ishakhsuvarov

@ivanweiler, thank you for your report. We've created internal ticket(s) MAGETWO-78706 to track progress on the issue.

magento-engcom-team avatar Sep 25 '17 22:09 magento-engcom-team

@magento-engcom-team Please see the second comment on the issue. I believe that your recently opened MAGETWO-78706 is actually duplicate of MAGETWO-43095 which has been opened for a year and half now...

udovicic avatar Sep 26 '17 10:09 udovicic

omg really reported 3 Mar 2016 and not fixed... a big WOW to the magento2 team. A major checkout issue lasting for over 1.5 years... could pls a magento management team member write a feedback here which internal processes are going totally wrong?

andidhouse avatar Sep 26 '17 10:09 andidhouse

We ran into the same issue for one of our clients.

This doesn't qualify to close the current issue, but it's a work-around so that at least the customer won't see outdated prices.

diff --git app/code/CleanCheckout/DynamicCart/etc/module.xml app/code/CleanCheckout/DynamicCart/etc/module.xml
new file mode 100644
index 00000000000..5574fba777d
--- /dev/null
+++ app/code/CleanCheckout/DynamicCart/etc/module.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
+    <module name="CleanCheckout_DynamicCart" setup_version="1.0.0">
+        <sequence>
+            <module name="Magento_Customer" />
+        </sequence>
+    </module>
+</config>
diff --git app/code/CleanCheckout/DynamicCart/registration.php app/code/CleanCheckout/DynamicCart/registration.php
new file mode 100644
index 00000000000..0a3a1b9e408
--- /dev/null
+++ app/code/CleanCheckout/DynamicCart/registration.php
@@ -0,0 +1,9 @@
+<?php
+
+use Magento\Framework\Component\ComponentRegistrar;
+
+ComponentRegistrar::register(
+    ComponentRegistrar::MODULE,
+    'CleanCheckout_DynamicCart',
+    __DIR__
+);
diff --git app/code/CleanCheckout/DynamicCart/view/frontend/requirejs-config.js app/code/CleanCheckout/DynamicCart/view/frontend/requirejs-config.js
new file mode 100644
index 00000000000..433657b3932
--- /dev/null
+++ app/code/CleanCheckout/DynamicCart/view/frontend/requirejs-config.js
@@ -0,0 +1,9 @@
+var config = {
+    config: {
+        mixins: {
+            'Magento_Customer/js/customer-data': {
+                'CleanCheckout_DynamicCart/js/customer-data-mixin': true
+            }
+        }
+    }
+};
\ No newline at end of file
diff --git app/code/CleanCheckout/DynamicCart/view/frontend/web/js/customer-data-mixin.js app/code/CleanCheckout/DynamicCart/view/frontend/web/js/customer-data-mixin.js
new file mode 100644
index 00000000000..3ae1ecedc53
--- /dev/null
+++ app/code/CleanCheckout/DynamicCart/view/frontend/web/js/customer-data-mixin.js
@@ -0,0 +1,24 @@
+define(['underscore'], function (_) {
+    'use strict';
+
+    return function (target) {
+        /**
+         * We can't use extends here, so create a copy of the original function.
+         */
+        target.getExpiredOriginal = target.getExpiredSectionNames;
+
+        target.getExpiredSectionNames = function() {
+            /**
+             * Retrieve original expired sections.
+             */
+            var expired = target.getExpiredOriginal();
+
+            /**
+             * Always expire the cart.
+             */
+            expired.push('cart');
+            return _.uniq(expired);
+        };
+        return target;
+    }
+});

It essentially makes sure that the cart section is expired in local storage on every request. This section update call only takes ~100ms for us, and doesn't block rendering. So we're pretty happy with the results.

Hope it helps someone!

cleancheckout avatar Oct 27 '17 16:10 cleancheckout

#mageconf

kvydiuk avatar Dec 15 '17 09:12 kvydiuk

@breg-13 thank you for joining. Please accept team invitation here and self-assign the issue.

magento-engcom-team avatar Dec 15 '17 10:12 magento-engcom-team

More use cases for this issue: https://github.com/magento/magento2/issues/9043

ishakhsuvarov avatar Mar 06 '18 13:03 ishakhsuvarov

One more: https://github.com/magento/magento2/issues/8579

orlangur avatar Mar 13 '18 15:03 orlangur

Additional use case: #3566

magento-engcom-team avatar Apr 26 '18 16:04 magento-engcom-team

I have the same issue on Magento 2.2.3, does anyone has a fix ?

Thanks !

magento2dev avatar Jul 23 '18 14:07 magento2dev