2

I have create problematically adding number of products at a time in Magento 2 cart and there I can one see one first product in mini cart other products are also in mini-cart but not showing the count and price

here is the code that i tried to update mini-cart

app/code/Multiple/Addtocart/etc/module.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Multiple_Addtocart" setup_version="2.1.1">
   </module>
   </config>

app/code/Multiple/Addtocart/view/frontend/layout/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="Multiple_Addtocart::refreshMinicart.phtml"  />
    </referenceContainer>
  </body>
</page>

app/code/Multiple/Addtocart/view/frontend/templates/refreshMinicart.phtml

<?php
?>
<script>
  require([
    'Magento_Customer/js/customer-data'
  ], function (customerData) {
    var sections = ['cart'];
    customerData.invalidate(sections);
  });
</script>

But here i'm getting object not created error

enter image description here

4
  • have you added Magento_Customer in your module.xml as sequence? Sep 27, 2017 at 6:22
  • @ chirag no how can i add this? checkout my updated code i have added my module.xml file
    – amith lal
    Sep 27, 2017 at 6:32
  • check my answer Sep 27, 2017 at 6:42
  • @ chirag got any idea?
    – amith lal
    Sep 27, 2017 at 9:35

2 Answers 2

1

Please add sections.xml file under

etc -> fronted -> sections.xml

<?xml version="1.0"?>

  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="checkout/cart/add">
       <section name="cart"/>
    </action>

1
  • i have tried this code but no change please check my updated question with image
    – amith lal
    Sep 27, 2017 at 4:35
0

Have you add Magento_Customer in your vendor/module/etc/module.xml?

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
   <module name="Vendor_Module" setup_version="1.0.0">
    <sequence>
        <module name="Magento_Customer"/>  
    </sequence>
  </module>
</config>
6
  • in my question i have added the code app/code/Multiple/Addtocart/view/frontend/templates/refreshMinicart.phtml is there any change for this also is this require now?
    – amith lal
    Sep 27, 2017 at 6:51
  • no changes, that is also required. is it working? Sep 27, 2017 at 6:57
  • its not getting worked yet i dont know why my minicart not getting updated but in cart everything is ok is there any other way do you have any idea to update minicart or relod it the mini cart will only update when we change quantity or delete anything from minicart
    – amith lal
    Sep 27, 2017 at 7:51
  • can you share your site url? Sep 27, 2017 at 8:05
  • @ chirag dealer.xtrememats.desirewebbies.com/products.html
    – amith lal
    Sep 27, 2017 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.