Skip to content

Instantly share code, notes, and snippets.

@gterrill
Last active December 2, 2016 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gterrill/3dced6af6f2c3f4d965261edd829f16f to your computer and use it in GitHub Desktop.
Save gterrill/3dced6af6f2c3f4d965261edd829f16f to your computer and use it in GitHub Desktop.
Debut theme (Slate) changes to support bundle availability check
// 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