Back to Top

Create your custom JavaScript event in PrestaShop 1.7

Updated 19 April 2022

In this blog, we are going to learn how to create your own JavaScript event in PrestaShop 1.7. In PrestaShop 1.7, there are already some JavaScript events are available like updatedCart, updateProduct, clickQuickView, etc. You can check the list of available JavaScript events using the below link:

https://devdocs.prestashop.com/1.7/themes/reference/javascript-events/

Dispatch an event

The best way to trigger an event is to use the prestashop object. Here is the syntax:

prestashop.emit(
    'yourCustomEventName', 
    { 
        Event data 
    }
);

For example:

prestashop.emit(
    'wkCustomJsEventMsg', 
    { 
        title: 'Success', 
        message: 'This is custom test event.' 
    }
);

Listening to events

You can listen to this event emitted by prestashop.emit using the prestashop object. Here is the syntax:

Searching for an experienced
Prestashop Company ?
Find out More
prestashop.on(
    'yourCustomEventName',
    function (eventData) {
        // do your stuff here with eventData variable
    }
);

For example:

prestashop.on(
    'wkCustomJsEventMsg',
    function (event) {
        $.growl.notice(
            { 
                title: event.title, 
                message: event.message 
            }
        );
    }
);

In this example, I have displayed the custom title and the message passed through prestashop.emit method. We listen to wkCustomJsEventMsg event and display the message.

image-52
Event message

You can also check our blogs related to this topic:

That’s all.

If any issue or doubt in the above process, please feel free to let us know in the comment section.

I would be happy to help.

Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

For any doubt contact us at support@webkul.com.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home