1

I have a javascript file like this:

jQuery(document).ready(function($){
 var mainWindown = top.document;
 test = {
 teesping_vesrion : '1.0.0',
 mainStuff : function(){
 var vars = {};
 this.doStuff();
 //refesh mini cart here
 },
 doStuff : function(){
 ......
 }
 )
})

i want to reload the minicart in my mainStuff function, but i dont know how to integrate the below code to my javascript file, which is to reload minicart:

<script>
 require([
 'Magento_Customer/js/customer-data'
 ], function (customerData) {
 var sections = ['cart'];
 customerData.invalidate(sections);
 });
</script>
asked May 4, 2017 at 10:08
1
  • You can try with, var miniCart = $('[data-block=\'minicart\']'); miniCart.trigger('contentUpdated'); Commented May 4, 2017 at 10:14

1 Answer 1

1

As Rakesh said in the comment you can trigger the content to be updated:

miniCart = $('[data-block=\'minicart\']');
miniCart.trigger('contentUpdated');

You can see this used in minicart.js

Notes

Related tip: To run your script on page load it's better to use domReady! as a dependency rather than use the jquery document ready method. domReady! makes sure other dependant scripts are aware of the dom ready requirement.

answered May 4, 2017 at 10:39
2
  • when i call the function for the first time it reload the minicart but, when i try run the function for the second time it didn't do anything Commented May 5, 2017 at 3:39
  • @Hunter Hmmmm what happens if you extend Magento/Checkout/view/frontend/web/js/view/minicart.js and use miniCart.sidebar('update');? Commented May 5, 2017 at 8:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.