javascript events prestashop 1.7

Dispatched events


updateCartOn the cart page, everytime something happens (change quantity, remove product and so on) the cart is reloaded by ajax call. After the cart is updated, this event is triggered.
updateAddressFormIn the address form, some input will trigger ajax calls to modify the form (like country change), after the form is updated, this event is triggered.
updateDeliveryFormDuring checkout, if the delivery address is modified, this event will be trigged.
changedCheckoutStepEach checkout step submission will fire this event.
updateProductListOn every product list page (category, search results, pricedrop and so on), the list is updated via ajax calls if you change filters or sorting options. Each time the DOM is reloaded with new product list, this event is triggered.
clickQuickViewIf your theme handles it, this event will be trigged when use click on the quickview link.
updateProductOn the product page, selecting a new combination will reload the DOM via ajax calls. After the update, this event is fired.
handleErrorThis event is fired after a fail of POST request. Have the eventType as first parameter.
updateFacesOn every product list page (category, search results, pricedrop and so on), the list is updated via ajax calls if you change filters or sorting options. Each time the facets is reloaded, this event is triggered.
responsive updateWhile broswer is resized, this event is fired with a mobile parameter.
EXAMPLE

prestashop.on(
    'updateFacets',
    function (event) {
        alert(event);
    }
     );
-------------------------------------------------------------------------------------------------------------------
         $(document).ready(function () {

            if(typeof prestashop !== 'undefined') {
                prestashop.on(
                  'updateCart',
                  function (event) {
                    if(typeof event.reason.linkAction !== "undefined" && event.reason.linkAction == "add-to-cart") {
                        if (typeof event.reason.idProduct == "undefined" || event.reason.idProduct == "undefined") {
                            // Bulletproofed action
                        }
                    }
                  }
                );
            }

         });


if(typeof prestashop !== 'undefined') {
                 prestashop.on(
                   'updateProductList',
                   function (event) {
console.log(event);
                  
                   }
                 );

Second Example


                 prestashop.on('updateProductList', (data) => {

                    
                       updateProductListDOM(data);
//other action
                    
                      });


            }


function updateProductListDOM (data) {
  $('#search_filters').replaceWith(data.rendered_facets);
  $('#js-active-search-filters').replaceWith(data.rendered_active_filters);
  $('#js-product-list-top').replaceWith(data.rendered_products_top);
  $('#js-product-list').replaceWith(data.rendered_products);
  $('#js-product-list-bottom').replaceWith(data.rendered_products_bottom);

}

Comments

Post a Comment

Popular Posts