最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prestashop - how to catch cart update - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 3

I 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) });

发布评论

评论列表(0)

  1. 暂无评论