admin管理员组文章数量:1426455
I'm writing a module to Prestashop. My module adds a small widget on cart view. The content of widget depends on cart content. My question is how to update my widget when user changes quantity of product or removes product from cart. This action is done via AJAX, so page is not refreshed and my widget is not refreshed as well. It would by nice find solution that doesn't require changes in templates - installing module should by enough.
Thanks, amos
I'm writing a module to Prestashop. My module adds a small widget on cart view. The content of widget depends on cart content. My question is how to update my widget when user changes quantity of product or removes product from cart. This action is done via AJAX, so page is not refreshed and my widget is not refreshed as well. It would by nice find solution that doesn't require changes in templates - installing module should by enough.
Thanks, amos
Share Improve this question asked Jun 8, 2017 at 10:03 amosamos 212 silver badges3 bronze badges 3- Dont really know anything about whatever it is you are talking about, but I guess you could always listen for ajax responses – musefan Commented Jun 8, 2017 at 10:05
- On the callback of the AJAX request that changes the cart you could run a JS script to change the contents of your widget – Dennis de Best Commented Jun 8, 2017 at 11:20
- @DennisdeBest thanks, that is exactly what I need to do. One more question: is there a valid cart content somewhere? Because AJAX response doesn't have it. There is also JS object prestashop.cart but it doesn't change after AJAX request. – amos Commented Jun 8, 2017 at 12:06
1 Answer
Reset to default 3I am using PrestaShop 1.7 and have used the following code to grab the response and update my cart icon.
Documentation can be found here: http://developers.prestashop./themes/javascript/index.html
prestashop.on('updatedCart', function(event) {
$('.nav-container .shopping-cart .shopping-cart-icon-count').text(this.cart.products_count)
});
本文标签: javascriptPrestashophow to catch cart updateStack Overflow
版权声明:本文标题:javascript - Prestashop - how to catch cart update - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745478974a2660092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论