[英]How can i listen to Prestashop events in custom.js?
在已編譯的theme.js中,我可以找到事件偵聽器,例如prestashop.on("updatedProduct")
和prestashop.on("clickQuickView")
。 更多關於這里 。
我無法使Web Pack正常工作,所以我只想在custom.js中添加一個偵聽器(我知道這是不好的做法,我只需要一個快速的解決方案)。
我如何在custom.js中引用此prestashop
,以便可以監聽諸如updateProductList
類的事件?
這是一個防彈的答案:
$(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
}
}
}
);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.