PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

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

 October 27, 2022     javascript, prestashop, prestashop-1.7     No comments   

Issue

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?


Solution

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
                        }
                    }
                  }
                );
            }

         });


Answered By - Matt Loye
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing