Last active
October 12, 2017 19:38
-
-
Save boldsupport/3a5a94acb5ed99f0f894a0337394d2c2 to your computer and use it in GitHub Desktop.
Buy the Measurement - Used to make the qty value render differently. Still used by Tier 2 and installs. Linked from: https://support.boldcommerce.com/hc/en-us/articles/208631356-Upgraded-Install-Instructions-for-Buy-the-Measure-includes-Product-Options-Premium-Support
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
<!-- bold-btm-upgrade-fields.liquid --> | |
{% comment %} Last Updated: 2017-01-06 {% endcomment %} | |
{% capture bold_btm_upgrade_fields_liquid %} | |
{% comment %} | |
BOLD-BTM-UPGRADE-FIELDS.LIQUID - Upgrades Buy the Measure to work with Premium (Priced) Product Options | |
USED BY: Buy the Measure | |
To use this file: | |
* Include this on the product.liquid page with the other BTM initialization scripts | |
Example: {% include 'bold-btm-upgrade-fields' %} | |
{% endcomment %} | |
<script> | |
var Bold = Bold || {}; | |
Bold.upgradeBTMFields = Bold.upgradeBTMFields || function(form){ | |
var $form = jQuery(form); | |
$form.find('.btm_upgrade').remove(); /*Remove the BTM upgrade fields (if they exist) before adding new ones*/ | |
$form.find('.btm_quantity_input[name="properties[quantity]"]').attr('name', '_btm_quantity'); | |
if($form.find('.bold-btm .measurement_div').length){ | |
var btm_qty = 1; | |
if($form.find('.btm_quantity_input').length) | |
btm_qty = parseInt($form.find('.btm_quantity_input').attr('name', "_btm_quantity").val()); | |
else | |
$form.prepend('<input type="hidden" class="btm_upgrade btm_qty" name="_btm_quantity" value=' + btm_qty + '>'); | |
var true_qty = parseInt($form.find('[name="quantity"]').last().val()); | |
var btm_ratio = true_qty / btm_qty; | |
var option_qty_input = '<input type="hidden" class="btm_upgrade btm_options" name="quantity" value=' + btm_qty + '>'; | |
var btm_ratio_input = '<input type="hidden" class="btm_upgrade btm_ratio" name="properties[_btm_ratio]" value=' + btm_ratio + '>'; | |
$form.prepend(option_qty_input).prepend(btm_ratio_input); | |
} | |
}; | |
jQuery(document).on('click', 'form[action*="cart/add"] [type="submit"]', function(){ | |
Bold.upgradeBTMFields(jQuery(this).closest('form')); | |
}); | |
</script> | |
{% endcapture %}{{ bold_btm_upgrade_fields_liquid | strip_newlines}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment