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! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024