Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi all,
I've been looking for any kind of documentation or reference material to find out what types of event listeners are available for Shopify events on the Online Store channel. So far I've stumbled across these two:
document.addEventListener('variant:changed', function(event) {
// Do things
});
document.addEventListener('product:added', function(event) {
// Do other things
});
I've tried guessing what other types of events there might be to no avail. I've also seen reference to other cart events - I'd be very interested in getting a list of all the product and cart events that are available!
Any assistance appreciated 😀
*bump* anyone with any ideas or pointers for this?
Hey I'm using Debut theme, and I've accomplished this by finding the actions/functions in the theme.js, for example: "
_onRemoveItem or _addItemToCart etc.
I'm chaining an extra "then" promise (before catch) to the function, like:
.then(function(result) {
let event = new Event("customEvent", {bubbles: true}); // (2)
document.dispatchEvent(event);
})
Then in my custom.js file I can listen into that event with:
document.addEventListener("customEvent", function(event) {
//console.log('lost now found')
});
I don't like modifying the theme.js file tbh, but at least this way I keep the core edits to a minimum and can maintain my custom.js away from the core theme files as much as possible.
If you want to review events being fired, use chrome inspector Network tab and watch for XHR requests to find the "initiator" see the image:
That would be the initial ajax request that we need to append an extra then promise to.
I wish it were more simple!
Dawn theme seems to publish events. However, when I try to add event listeners to these events, nothing ever happens.
Here is the code in Dawn theme that fires the event when you add something to the cart:
in product-form.js around line 68:
Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-TekLabs to discuss practical strategies for...
By JasonH Nov 13, 2024The year-end shopping spree is around the corner! Is your online store ready for the ...
By JasonH Nov 10, 2024