Created
December 15, 2014 21:50
-
-
Save mikekavouras/51fdaf6b8a4fa63b0ec1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{% comment %} | |
A snippet to include related products on a product single page. | |
More information: | |
- http://docs.shopify.com/support/your-store/products/can-i-recommend-related-products | |
{% endcomment %} | |
{% assign number_of_related_products_to_show = 4 %} | |
{% assign number_of_related_products_to_fetch = number_of_related_products_to_show | plus: 1 %} | |
{% if collection == null or collection.handle == 'frontpage' or collection.handle == 'all' %} | |
{% assign found_a_collection = false %} | |
{% for c in product.collections %} | |
{% if found_a_collection == false and c.handle != 'frontpage' and c.handle != 'all' and c.all_products_count > 1 %} | |
{% assign found_a_collection = true %} | |
{% assign collection = c %} | |
{% endif %} | |
{% endfor %} | |
{% endif %} | |
{% assign show_featured = false %} | |
{% for article in blogs.tiles.articles %} | |
{% for tag in article.tags %} | |
{% if product.tags contains tag %} | |
{% assign show_featured = true %} | |
{% endif %} | |
{% endfor %} | |
{% endfor %} | |
{% if collection and collection.products_count > 0 or show_featured %} | |
{% if show_featured %} | |
<div class="grid-item large--one-half"> | |
<span class="h2">Featured in</span> | |
<div class="tile story"> | |
{% for article in blogs.tiles.articles %} | |
{% for tag in article.tags %} | |
{% if product.tags contains tag %} | |
<div style=""> | |
{{article.content}} | |
</div> | |
{% endif %} | |
{% endfor %} | |
{% endfor %} | |
</div> | |
</div> | |
{% endif %} | |
{% if collection and collection.products_count %} | |
{% if show_featured %} | |
{% assign grid_item_width = 'large--one-half medium--one-half' %} | |
<div class="grid-item large--one-half"> | |
{% else %} | |
<div class="grid-item large--one-full"> | |
{% endif %} | |
<span class="h2">{{ settings.related_products_title }}</span> | |
{% assign current_product = product %} | |
{% assign current_product_found = false %} | |
{% for product in collection.products limit: number_of_related_products_to_fetch %} | |
{% if product.handle == current_product.handle %} | |
{% assign current_product_found = true %} | |
{% else %} | |
{% unless current_product_found == false and forloop.last %} | |
{% assign from_related = true %} | |
{% include 'product-grid-item' %} | |
{% endunless %} | |
{% endif %} | |
{% endfor %} | |
</div> | |
{% endif %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment