Last active
January 24, 2020 16:14
-
-
Save vvastdev/accd534955612605de765d6fd1501af6 to your computer and use it in GitHub Desktop.
product.js variant availability handling
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
//called in initVariants | |
_handleColourAvailability: function(data) { | |
if(this.variantRadios){ | |
var variants = data.product.variants; | |
var coloursAvailable = {}; | |
variants.forEach( variant => { | |
if(variant.available){ | |
coloursAvailable[variant.option1] = true; | |
} | |
}) | |
this.variantRadios.forEach( radio => { | |
var col = radio.dataset.value; | |
if(!coloursAvailable.hasOwnProperty(col)){ | |
$(radio).css('display', 'none'); | |
} | |
}) | |
} | |
}, | |
//called in initVariants and _updateAvailabilty | |
_handleSizeAvailability: function(data, variantChange) { | |
var variants = data.product.variants; | |
var currentColour = variantChange ? variantChange.variant.option1 : data.currentVariant.option1; | |
var sizeUnavailable = {}; | |
variants.forEach( variant => { | |
if(!variant.available && variant.option1 === currentColour){ | |
sizeUnavailable["size"] = variant.option2; | |
} | |
}) | |
this.sizeRadios.forEach( radio => { | |
sizeValue = radio.dataset.sizeValue; | |
sizeUnavailable.size === sizeValue ? | |
$(radio).addClass('size-unavailable') : | |
$(radio).removeClass('size-unavailable'); | |
}) | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment