Created
February 21, 2012 19:13
-
-
Save carolineschnapp/1878238 to your computer and use it in GitHub Desktop.
When filtering a collection by size, say, 'Small', that is the code to use to hide products which 'Small' variants are out of stock.
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
{% for product in collection.products %} | |
{% assign hide_product = false %} | |
{% assign size_index = 0 %} | |
{% for option in product.options %} | |
{% if option == 'Size' %} | |
{% assign size_index = forloop.index0 %} | |
{% endif %} | |
{% endfor %} | |
{% assign filter_by_size = false %} | |
{% assign filtered_size = '' %} | |
{% for tag in current_tags %} | |
{% if tag == 'Small' or tag == 'Medium' or tag == 'Large' %} | |
{% assign filter_by_size = true %} | |
{% assign filtered_size = tag %} | |
{% endif %} | |
{% endfor %} | |
{% if filter_by_size %} | |
{% assign at_least_one_item_in_stock = false %} | |
{% for variant in product.variants %} | |
{% if variant.options[size_index] == filtered_size and variant.available %} | |
{% assign at_least_one_item_in_stock = true %} | |
{% endif %} | |
{% endfor %} | |
{% unless at_least_one_item_in_stock %} | |
{% assign hide_product = true %} | |
{% endunless %} | |
{% endif %} | |
{% if product.available %} | |
{% unless hide_product %} | |
[ LIQUID AND HTML FOR YOUR PRODUCT ] | |
{% endunless %} | |
{% endif %} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment