Last active
December 2, 2016 00:06
-
-
Save gterrill/3dced6af6f2c3f4d965261edd829f16f to your computer and use it in GitHub Desktop.
Debut theme (Slate) changes to support bundle availability check
This file contains hidden or 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
// theme.liquid | |
<script> | |
window.addEventListener("load", function(event) { | |
$('.single-option-selector').trigger('change'); // trigger bundle check on initial variant | |
}); | |
</script> | |
// theme.js - line 2438 | |
_updateAddToCart: function(evt) { | |
var variant = evt.variant; | |
if (variant) { | |
$(this.selectors.productPrices) | |
.removeClass('visibility-hidden') | |
.attr('aria-hidden', 'true'); | |
var _this = this, | |
quantityField = $('input[name=quantity]'); | |
bundled(variant, function(bundle) { | |
if (variant.available && bundle.available) { | |
$(_this.selectors.addToCart).prop('disabled', false); | |
$(_this.selectors.addToCartText).text(theme.strings.addToCart); | |
quantityField.attr('max', bundle.quantity); | |
quantityField.val(Math.min(bundle.quantity, quantityField.val())); | |
} else { | |
// The variant doesn't exist, disable submit button and change the text. | |
// This may be an error or notice that a specific variant is not available. | |
$(_this.selectors.addToCart).prop('disabled', true); | |
$(_this.selectors.addToCartText).text(theme.strings.soldOut); | |
} | |
}); | |
} else { | |
$(this.selectors.addToCart).prop('disabled', true); | |
$(this.selectors.addToCartText).text(theme.strings.unavailable); | |
$(this.selectors.productPrices) | |
.addClass('visibility-hidden') | |
.attr('aria-hidden', 'false'); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment