Skip to content

Instantly share code, notes, and snippets.

@dylanjhunt
Created April 20, 2020 13:16
Show Gist options
  • Select an option

  • Save dylanjhunt/e88ea265b014eaf3673798a08148cc5f to your computer and use it in GitHub Desktop.

Select an option

Save dylanjhunt/e88ea265b014eaf3673798a08148cc5f to your computer and use it in GitHub Desktop.
Show all products as separate variants on the collection page of the Venture Theme
<!-- /snippets/product-card.liquid -->
{% comment %}
The product card snippet is passed a liquid object, used in this file
as "product". The object is either "product" or "item", the latter if
it is from search results.
{% endcomment %}
<a href="{{ variant.url | within: collection }}" class="product-card">
{% comment %} <img src="{{ variant.image.src | img_url: '480x480' }}" alt="{{ variant.image.alt | escape }}" class="product-card__image"> {% endcomment %}
{% if variant.image %}
{% assign image = variant.image %}
{% else %}
{% assign image = product.featured_image %}
{% endif %}
<div class="product-card__image-container">
<div class="product-card__image-wrapper">
<div class="product-card__image js" style="max-width: {% include 'image-width' with image: image, width: 235 %}px;" data-image-id="{{ image.id }}">
<div style="padding-top:{{ 1 | divided_by: image.aspect_ratio | times: 100 }}%;">
{% assign img_url = image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' %}
<img class="lazyload"
data-src="{{ img_url }}"
data-widths="[100, 140, 180, 250, 305, 440, 610, 720, 930, 1080]"
data-aspectratio="{{ image.aspect_ratio }}"
data-sizes="auto"
data-parent-fit="contain"
alt="{{ image.alt | escape }}">
</div>
</div>
<noscript>
<img src="{{ variant.image.src | img_url: '480x480' }}" alt="{{ product.featured_image.alt | escape }}" class="product-card__image">
</noscript>
</div>
</div>
<div class="product-card__info">
{% if settings.product_vendor_enable %}
<div class="product-card__brand">{{ product.vendor }}</div>
{% endif %}
<div class="product-card__name">{{ product.title }}</div>
{% if product.available %}
<div class="product-card__price">
{% if variant.compare_at_price > variant.price %}
{% comment %}
Product is on sale
{% endcomment %}
{% if variant.price_varies %}
{% assign sale_price = variant.price | money_without_trailing_zeros %}
{{ 'products.product.on_sale_from_html' | t: price: sale_price }}
{% else %}
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
<s class="product-card__regular-price">{{ variant.compare_at_price | money_without_trailing_zeros }}</s>
<span class="visually-hidden">{{ 'products.product.sale_price' | t }}</span>
{{ variant.price | money_without_trailing_zeros }}
{% endif %}
{% else %}
{% comment %}
Not on sale, but could still have varying prices
{% endcomment %}
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
{{ variant.price | money_without_trailing_zeros }}
{% endif %}
</div>
{% else %}
<div class="product-card__availability">
{{ 'products.product.sold_out' | t }}
</div>
{% endif %}
</div>
{% if variant.compare_at_price > variant.price %}
{% comment %}
A visually-hidden label before regular/sale prices clarifies
prices for screen readers, so hide the sale tag from them.
{% endcomment %}
<div class="product-tag product-tag--absolute" aria-hidden="true">
{{ 'products.product.on_sale' | t }}
</div>
{% endif %}
<div class="product-card__overlay">
{% assign view_string_length = 'products.product.view' | t | size %}
<span class="btn product-card__overlay-btn {% if view_string_length > 8 %} btn--narrow{% endif %}">{{ 'products.product.view' | t }}</span>
</div>
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment