javascript events prestashop 1.7
Dispatched events
updateCart | On 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. |
updateAddressForm | In 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. |
updateDeliveryForm | During checkout, if the delivery address is modified, this event will be trigged. |
changedCheckoutStep | Each checkout step submission will fire this event. |
updateProductList | On 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. |
clickQuickView | If your theme handles it, this event will be trigged when use click on the quickview link. |
updateProduct | On the product page, selecting a new combination will reload the DOM via ajax calls. After the update, this event is fired. |
handleError | This event is fired after a fail of POST request. Have the eventType as first parameter. |
updateFaces | On 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 update | While broswer is resized, this event is fired with a mobile parameter. |
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);
}
Great post.
ReplyDeletehttp://www.icoph.org/connections/user_profile/0033o00003skeMbAAI/John-D-Bailey.html
Great post
ReplyDeletehttps://vimeo.com/solawoods