Magento 2.1 – Mini Cart Not Showing Product on First Add

addtocartmagento-2.1mini-cart

I am using Ultimo Infortis theme. I am facing issue in adding product to mini cart. First time when i click on Add to Cart button, it do not show product in mini cart but on cart page it show added product. If i again add product to cart then mini cart show added products lists.

This is happening form the first day. I disabled magento cache but still the issue is there.

Can anyone suggest me how to fix this issue.

Best Answer

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>

EDIT

/app/design/frontend/Magento/luma/Magento_Theme/layout/default.xml

/app/design/frontend/Magento/luma/Magento_Theme/templates/refreshMinicart.phtml

or if you have created module then you can paste at

app/code/Vendor/Module/view/frontend/layout/

app/code/Vendor/Module/view/frontend/templates/

Related Topic