Menu Close
    Hire us Request quote Reading list Switch to dark mode

    Update Mini Cart Magento2

    In this blog we will see how to update mini cart in magento2.
    In Magento2 many times it happens, You changed something in cart but it does not reflects in mini cart.
    It happens when you try to change and update cart items programmatically.

    There can be two types of situation.

    • When you are updating cart by submitting form.
    • When you are updating cart without submitting form.

    Update mini cart when you are submitting a form

    Magento provides a way to update minicart if you are submitting a form.
    First of all create sections.xml file in ‘etc/frontend’ folder in your module.
    Now write following code snippet in sections.xml file


    action name : action name is controller where you are submitting form.
    So Use this approach whenever you are dealing with a form.
    Example of this situation may be when you want to set custom price of product in your own controller.
    This approach will work when you are using POST or PUT form submitting. It will also work for AJAX request.

    Update mini cart when you are not submitting a form

    In some situations you want to update cart and you don’t want to submit any form.

    In these type of situations you can not use sections.xml file because you are not submitting a form.

    So for these type of situations you can use following code in template file.


    So use this code snippet in phtml file and minicart will be updated.
    Example of this situation may be when you want to add and update items in cart on cart view and checkout page.
    So using these two approaches you can update mini cart in any type of situation.

    If you have any issue or query, comment below.

    . . .

    Comments (3)

    Add Your Comment

  • Rajendra pawar
    Awesome ! Thanks you !
    • Hari Narayan Bairwa
      Thank you for your appreciation. Further, if you have any other query or requirement then you can mail us at support@webkul.com
  • Dominic Dambrogia
    Could you elaborate on updating the minicart without submitting a form? From a logical standpoint it looks like you are invalidating the minicart. Does this force the minicart to be validated after invalidation?
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again
    Close