Last active
December 27, 2015 16:39
-
-
Save kyleaparker/7356064 to your computer and use it in GitHub Desktop.
Inventory Quantity Table for up to two options
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
<div id="inventory"> | |
<h3>Inventory Available</h3> | |
{% assign options1 = product.variants | map: "option1" %} | |
<table> | |
<tr> | |
{% if product.options.size > 1 %}<th> </th>{% endif %} | |
{% assign options1Filtered = '' %} | |
{% for option1 in options1 %} | |
{% assign option1Space = option1 | prepend: ', ' %} | |
{% unless options1Filtered contains option1Space %} | |
<th><strong>{{ option1 }}</strong></th> | |
{% assign options1Filtered = options1Filtered | append: ', ' | append: option1 %} | |
{% endunless %} | |
{% endfor %} | |
</tr> | |
{% if product.options.size > 1 %} | |
{% assign options2 = product.variants | map: "option2" %} | |
{% assign options2Filtered = '' %} | |
{% assign options1Split = options1Filtered | remove_first: ', ' | split: ', ' %} | |
{% assign index = 1 %} | |
{% for option2 in options2 %} | |
<tr> | |
{% assign optionSpace = option2 | prepend: ', ' %} | |
{% unless options2Filtered contains optionSpace %} | |
<td><strong>{{ option2 }}</strong></td> | |
{% for option1 in options1Split %} | |
{% assign variantFound = false %} | |
<td> | |
{% for variant in product.variants %} | |
{% if variant.option1 == option1 and variant.option2 == option2 %} | |
{{ variant.inventory_quantity }} | |
{% assign variantFound = true %} | |
{% endif %} | |
{% if forloop.last and variantFound == false %}N/A{% endif %} | |
{% endfor %} | |
</td> | |
{% endfor %} | |
{% assign options2Filtered = options2Filtered | append: ', ' | append: option2 %} | |
{% endunless %} | |
</tr> | |
{% endfor %} | |
{% else %} | |
<tr> | |
{% for variant in product.variants %} | |
<td>{{ variant.inventory_quantity }} </td> | |
{% endfor %} | |
</tr> | |
{% endif %} | |
</table> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment