Question

We have a strange behavior in our store in the mini cart. If I add some items to cart then navigate somewhere and after couple minutes content of mini cart disappears. If I add something again to mini cart - I will see all my previous items again.

Our team checks https settings (all store under https), cookie settings, session settings, cache settings etc. Nothing helps. Same thing always. Any thoughts what it could be?

M2 version: 2.1.2

Was it helpful?

Solution

That is magento2's default bug

https://github.com/magento/magento2/issues/5377

https://github.com/magento/magento2/issues/4170

for the temporary solution, you can refresh mini cart in all page for that you can use below code.

default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
    <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="refresh.minicart" template="{vendor}_{module}::refreshMinicart.phtml"  />
    </referenceContainer>
  </body>
</page>

refreshMinicart.phtml

<script>
  require([
    'Magento_Customer/js/customer-data'
  ], function (customerData) {
    var sections = ['cart'];
    customerData.invalidate(sections);
  });
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top