Created
February 5, 2018 18:27
-
-
Save essmahr/c19f0c899e25c98bbabe9e5ad84374f0 to your computer and use it in GitHub Desktop.
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
At the top, add: | |
{% include 'buyx-product' with product %} | |
{% include 'buyx-price-min' with product %} | |
The following blocks are original code, if exist, and replacement code. | |
==== | |
{% for option in product.options %} | |
... | |
{% endfor %} | |
== replace with ==> | |
{% for option in product.options %} | |
{% unless option contains 'BuyXDiscount' %} | |
... | |
{% endunless %} | |
{% endfor %} | |
==== | |
{% for variant in product.variants %} | |
... | |
{% endfor %} | |
== replace with ==> | |
{% for variant in product.variants %} | |
{% unless variant.title contains '% Off' %} | |
... | |
{% endunless %} | |
{% endfor %} | |
==== | |
{% if product.options.size > 1 %} | |
== replace with ==> | |
{% if buyx_product_options_size > 1 %} | |
==== | |
{% elsif product.options.size == 1 and product.variants.size > 1 %} | |
== replace with ==> | |
{% elsif buyx_product_options_size == 1 and buyx_product_variants_size > 1 %} | |
==== | |
and product.options.first != 'Title' | |
== replace with ==> | |
and product.options.first != 'Title' and product.options.first != 'BuyXDiscount' | |
==== | |
product.available | |
== replace with ==> | |
buyx_product_available | |
==== | |
product.price | |
product.price_min | |
== replace with ==> | |
buyx_price_min | |
==== | |
{% if product.price_varies %} | |
== replace with ==> | |
{% if product.price_max > buyx_price_min %} | |
==== | |
{% assign variant = product.selected_or_first_available_variant %} | |
== replace with ==> | |
{% assign variant = product.variants.first %} | |
{% for varianti in product.variants %} | |
{% unless varianti.title contains '% Off' %} | |
{% if varianti.available %} | |
{% assign variant = varianti %} | |
{% break %} | |
{% endif %} | |
{% endunless %} | |
{% endfor %} | |
==== | |
product.variants.size | |
== replace with ==> | |
buyx_product_variants_size | |
==== | |
/* for some themes, this is in theme.liquid, or main.js.liquid */ | |
new Shopify.OptionSelectors("product-select", { product: {{ product | json }}, onVariantSelected: selectCallback }); | |
== replace with ==> | |
{% include 'buyx-price-min' with product %} | |
{% if buyx_product_variants_size > 1 and buyx_product_available %} | |
{% endif %} | |
function buyx_product_json(product) { | |
if (product == null) { | |
return null | |
} | |
var variants = [] | |
//does it have BuyXDiscount option? | |
var option_position = -1 | |
for (var oi = 0, olen = product.options.length; oi < olen; oi++) { | |
if (product.options[oi] == "BuyXDiscount") { | |
option_position = oi+1 | |
break | |
} | |
} | |
if (option_position == -1) { | |
return product | |
} | |
if (product.options.length > 1) { | |
product.options.splice(option_position-1, 1) | |
} else { | |
product.options[0] = "Title" | |
} | |
option_position = "option" + option_position | |
product.available = false | |
for (var vi = 0, vlen = product.variants.length; vi < vlen; vi++) { | |
if (product.variants[vi][option_position] == "Default") { | |
//product.variants[vi][option_position] = "" | |
variants.push(product.variants[vi]) | |
product.available = product.available || product.variants[vi].available | |
} | |
} | |
product.variants = variants | |
return product | |
} | |
new Shopify.OptionSelectors(..., { product: buyx_product_json({{ product | json }}) , ... | |
==== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment