Skip to content

Instantly share code, notes, and snippets.

@zakhardage
Created March 15, 2014 19:12
Show Gist options
  • Select an option

  • Save zakhardage/9572288 to your computer and use it in GitHub Desktop.

Select an option

Save zakhardage/9572288 to your computer and use it in GitHub Desktop.
{% if customer and customer.tags contains 'wholesale' %}{% assign wholesale-customer = true %}{% endif %}
{% for variant in product.variants %}{% if variant.title contains 'wholesale' %}{% assign wholesale-product = true %}{% endif %}
{% assign price = product.price_max %}
{% if wholesale-customer and wholesale-product %}
{% for variant in product.variants %}
{% if variant.title contains 'wholesale %}
{% assign item-count = item-count | plus:1 %}
{% unless variant.price < price %}
{% assign id = variant.id %}
{% endunless %}
{% endif %}
{% endfor %}
{% else %}
{% for variant in product.variants %}
{% unless variant.title contains 'wholesale %}
{% assign item-count = item-count | plus:1 %}
{% unless variant.price < price %}
{% assign id = variant.id %}
{% endunless %}
{% endunless %}
{% endfor %}
{% endif %}
{% if item-count > 1 %}
<select name="id" id="product-select">
{% for variant in product.variants %}
{% if wholesale-customer and wholesale-product %}
{% if variant.title contains 'wholesale' %}
<option value="{{ variant.id }}">{{ variant.title }}</option>
{% endif %}
{% else %}
{% unless variant.title contains 'wholesale' %}
<option value="{{ variant.id }}">{{ variant.title }}</option>
{% endunless %}
{% endif %}
{% endfor %}
</select>
{% else %}
<input type="hidden" name="id" id="product-select" value="{{ id }}" />
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment