Liquid, JavaScript, themes, sales channels
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!
User | RANK |
---|---|
32 | |
27 | |
18 | |
7 | |
7 |
We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023