简体   繁体   English

如何在custom.js中收听Prestashop事件?

[英]How can i listen to Prestashop events in custom.js?

In the compiled theme.js i can find event listeners like prestashop.on("updatedProduct") and prestashop.on("clickQuickView") . 在已编译的theme.js中,我可以找到事件侦听器,例如prestashop.on("updatedProduct")prestashop.on("clickQuickView") More about those here . 更多关于这里

I cannot get the web pack to work, so i would like to just add a listener in the custom.js (i know this is bad practice, i just need a quick solution). 我无法使Web Pack正常工作,所以我只想在custom.js中添加一个侦听器(我知道这是不好的做法,我只需要一个快速的解决方案)。

How do i refer to this prestashop in custom.js, so i can listen for an event like updateProductList ? 我如何在custom.js中引用此prestashop ,以便可以监听诸如updateProductList类的事件?

Here is a bulletproof answer : 这是一个防弹的答案:

         $(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM