简体   繁体   中英

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") . 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).

How do i refer to this prestashop in custom.js, so i can listen for an event like 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
                        }
                    }
                  }
                );
            }

         });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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