0

I created a script that opens the minicart. Now adding product is made using JS/Ajax and I don't refresh the page. Now the problem is the Basket count is not being updated when I add to cart. Is there a way to manually triggers the headerCartUpdate function from Magento_Theme headerBasket.js?

So basically I want to call it after the ajaxSubmit of the catalog-add-to-cart.js

0

Magento fires 2 events in ajaxSubmit method event catalogCategoryAddToCartRedirect in code $('body').trigger('catalogCategoryAddToCartRedirect', eventData); fired if you set redirect to cart after add product configuration to true

The other one is contentUpdated in code $(self.options.minicartSelector).trigger('contentUpdated') if minicart is enabled.

You can subscribe to anyone based on your approach and execute your method.

You will need to add this code in

app/design/frontend/VendorName/ThemeName/Magento_Catalog/templates/product/list.phtml

<script type="text/javascript">
require(['jquery'], function($){
    $("body").on("contentUpdated", function(event){
        // here; you can run any logic on event then run your method
    });
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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