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)
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745478974a4629476.html
评论列表(0条)