/debug-product-alt-colours.liquid Secret
Last active
October 13, 2022 15:02
-
-
Save stephenkeable/db757259de19b18aaf82fb9cf032ed26 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
{%- assign tag_alt = "BLANK" -%} | |
{%- for tag in product.tags -%} | |
{%- assign tag_prefix = tag | slice: 0, 5 -%} | |
{%- if tag_prefix == "_alt_" -%} | |
{%- assign tag_alt = tag -%} | |
<!-- looking for tag {{ tag_alt }} --> | |
{%- break -%} | |
{%- else -%} | |
<!-- tag {{ tag }} has no "_alt" prefix --> | |
{%- endif -%} | |
{%- else -%} | |
<!-- no product tags found --> | |
{%- endfor -%} | |
{%- unless tag_alt == "BLANK" -%} | |
{%- assign vendor_handle = product.vendor | handle -%} | |
<!-- looking for collection /collections/{{vendor_handle}} --> | |
{%- if collections[vendor_handle].products.size > 0 -%} | |
{%- assign alt_products_total = 0 -%} | |
{%- capture products_output -%} | |
{%- paginate collections[vendor_handle].products by 200 -%} | |
{%- for alt_product in collections[vendor_handle].products -%} | |
{%- if alt_product.tags contains tag_alt -%} | |
{%- unless alt_product.id == product.id -%} | |
{%- assign alt_products_total = alt_products_total | plus: 1 -%} | |
<a href="{{ alt_product.url }}" title="{{ alt_product.title }}"><img src="{{ alt_product.featured_image | img_url: '90x90', crop: 'center', format: 'pjpg' }}" alt="{{ alt_product.title }}"></a> | |
{%- else -%} | |
<!-- product {{ alt_product.title }} is the current product so we skip --> | |
{%- endunless -%} | |
{%- else -%} | |
<!-- product {{ alt_product.title }} doesn't have the {{ tag_alt }} tag --> | |
{%- endif -%} | |
{%- else -%} | |
<!-- no products in the {{ vendor_handle }} collection --> | |
{%- endfor -%} | |
{%- endpaginate -%} | |
{%- endcapture -%} | |
{%- else -%} | |
<!-- {{ vendor_handle }} collection has no products or doesn't exist --> | |
{%- endif -%} | |
{%- else -%} | |
<!-- no tag_alt set --> | |
{%- endunless -%} | |
{%- if alt_products_total > 0 -%} | |
<br><br> | |
<p><strong>Also Available In:</strong></p> | |
<div class="product-alt-colours"> | |
{{ products_output }} | |
</div> | |
{%- else -%} | |
<!-- 0 products found --> | |
{%- endif -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment