1

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

amos
  • 21
  • 2
  • 3
  • Dont really know anything about whatever it is you are talking about, but I guess you could always [listen for ajax responses](https://stackoverflow.com/questions/5202296/add-a-hook-to-all-ajax-requests-on-a-page) – musefan Jun 08 '17 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 Jun 08 '17 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 Jun 08 '17 at 12:06

1 Answers1

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.com/themes/javascript/index.html

prestashop.on('updatedCart', function(event) { $('.nav-container .shopping-cart .shopping-cart-icon-count').text(this.cart.products_count) });

mamos
  • 31
  • 4