Skip to content

Instantly share code, notes, and snippets.

@vorvulev
Last active February 4, 2022 23:55
Show Gist options
  • Save vorvulev/54af71671b192e746e2831acc02017d9 to your computer and use it in GitHub Desktop.
Save vorvulev/54af71671b192e746e2831acc02017d9 to your computer and use it in GitHub Desktop.
Triggers the variant in product card
EventBus.subscribe('products-ready:insales:common', function(data) {
$("[data-founded]").each(function(index, el) {
var pid = parseInt($(el).attr("data-product-id")),
vid = parseInt($(el).attr("data-founded"));
$(el).removeAttr('data-founded');
Products._products[pid]._instance[0].variants.setVariant(vid);
});
});
EventBus.subscribe('change_variant:insales:product', function(data) {
data.action.product.find('a[href]').each(function(index, el) {
$(el).attr('href', $(el).attr('href').split('?variant_id')[0]+"?variant_id="+data.id+"");
});
});
Products._products[product_id]._instance[0].variants.setVariant(variant_id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment