我如何收听 custom.js 中的 Prestashop 事件?
How can i listen to Prestashop events in custom.js?
在编译的 theme.js 中,我可以找到像 prestashop.on("updatedProduct")
和 prestashop.on("clickQuickView")
这样的事件侦听器。
有关 here.
的更多信息
我无法让 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
}
}
}
);
}
});
在编译的 theme.js 中,我可以找到像 prestashop.on("updatedProduct")
和 prestashop.on("clickQuickView")
这样的事件侦听器。
有关 here.
我无法让 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
}
}
}
);
}
});