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>
-
You can try with, var miniCart = $('[data-block=\'minicart\']'); miniCart.trigger('contentUpdated');Rakesh Jesadiya– Rakesh Jesadiya2017年05月04日 10:14:11 +00:00Commented May 4, 2017 at 10:14
1 Answer 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.
-
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 anythingHunter– Hunter2017年05月05日 03:39:05 +00:00Commented May 5, 2017 at 3:39
-
@Hunter Hmmmm what happens if you extend
Magento/Checkout/view/frontend/web/js/view/minicart.jsand useminiCart.sidebar('update');?Ben Crook– Ben Crook2017年05月05日 08:34:24 +00:00Commented May 5, 2017 at 8:34
Explore related questions
See similar questions with these tags.