Created
June 16, 2020 20:26
-
-
Save nilocortex/285b1056ac1b21091dbd1e546e70e9c1 to your computer and use it in GitHub Desktop.
Add Variant ID Url switching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$container.on(theme.Variants.eventStrs.onVariantChanged, function (e, variant) { | |
if (variant) { | |
if(window.location.pathname.indexOf('product') >= 0){ | |
var newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?variant=' + variant.id; | |
window.history.replaceState({path: newurl}, '', newurl); | |
} | |
self._changeImage($container, variant); | |
self._changePrice($container, variant); | |
self._changeSKU($container, variant); | |
self._updateAvailability($container, variant.available); | |
$('.shopify-payment-button').show(); | |
self._changeMetafield($container, variant); | |
} else { | |
if(window.location.pathname.indexOf('product') >= 0){ | |
var newurl = window.location.protocol + '//' + window.location.host + window.location.pathname; | |
window.history.replaceState({path: newurl}, '', newurl); | |
} | |
$('.shopify-payment-button').hide(); | |
self._changePrice($container, null); | |
self._changeSKU($container, null); | |
self._updateAvailability($container, false, '{{ 'products.product.unavailable' | t }}'); | |
} | |
}); | |
//Set up the listener for when a new quantity is entered | |
$container.on(theme.Variants.eventStrs.onQtyChanged, function (e, newQuantity) { | |
var $selection = theme.Variants.getSelectedVariant($container); | |
self._updatePrice($container, $selection.data('base-price'), $selection.data('compare-price'), newQuantity); | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment