Skip to content

Instantly share code, notes, and snippets.

@dinhnguyen
Created July 23, 2015 01:28
Show Gist options
  • Save dinhnguyen/766485b9cf79949b5770 to your computer and use it in GitHub Desktop.
Save dinhnguyen/766485b9cf79949b5770 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
// <![CDATA[
var selectCallback = function(variant, selector) {
if (variant && variant.available == true) {
// selected a valid variant
jQuery('.purchase').removeClass('disabled').removeAttr('disabled'); // remove unavailable class from add-to-cart button, and re-enable button
jQuery('.price-field').html(Bizweb.formatMoney(variant.price, "{{store.money_with_currency_format}}")); // update price field
} else {
// variant doesn't exist
jQuery('.purchase').addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "Hết hàng" : "Ngừng bán";
jQuery('.price-field').text(message); // update price-field message
}
};
// initialize multi selector for product
jQuery(function() {
new Bizweb.OptionSelectors("product-select", { product: {{ product | json }}, onVariantSelected: selectCallback });
jQuery('.selector-wrapper').addClass('clearfix');
{% if product.options.size == 1 %}
jQuery('.selector-wrapper').prepend("<label for='product-select-option-0'>{{ product.options.first }}</label>");
{% endif %}
});
// ]]>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment