Files
Flex/snippets/related-items__variant-grid-item.liquid
T

192 lines
8.0 KiB
Plaintext
Raw Normal View History

2026-10-15 20:25:58 +08:00
{% comment %}
----------------
Optional values
product_recommendations: <boolean>
{% endcomment %}
{% comment %}Check for related products and increase limit by one (to offset the currently selected product that is removed from the product loop){% endcomment %}
{%- assign limit = limit | plus: 0 -%}
{%- assign loop_limit = limit | plus: 1 -%}
{%- assign hover_enabled = block.settings.show_related_products_title_on_hover -%}
{%- assign visible_products = products_per | plus: 0 -%}
{%- assign hover_enabled = settings.thumbnail_hover_enabled -%}
{% liquid
assign active_discount = true
assign empty_array = "" | split: ""
assign dormant_discounts = shop.metafields.app--168074346497.dormant_discounts.value | default: empty_array
assign target_discount_id = product.metafields.app--168074346497.applied_discount_id.value
for dormant_discount in dormant_discounts
if dormant_discount == target_discount_id
assign active_discount = false
endif
endfor
assign product_price = product.price
assign product_compare_at_price_max = product.compare_at_price_max
assign product_compare_at_price = product.compare_at_price
if active_discount
assign product_price = product.metafields.app--168074346497.min_auto_discounted_price.value | default: product.price
if product_price < product.price and product_compare_at_price == 0 or product_compare_at_price == blank
assign product_compare_at_price = product.price
endif
if product_price < product.price and product_compare_at_price_max == 0 or product_compare_at_price_max == blank
assign product_compare_at_price_max = product.price_max
endif
endif
assign variant_price = variant.price
assign variant_compare_at_price = variant.compare_at_price
if active_discount
assign variant_price = variant.metafields.app--168074346497.auto_discounted_price.value | default: variant.price
assign variant_compare_at_price = variant.compare_at_price
if shop.metafields.app--168074346497.discount_percentage.value > 0.005
assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0
assign deducted_percentage = 1.0 | minus: discount_percentage
assign variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
endif
if variant_price < variant.price and variant_compare_at_price == 0 or variant_compare_at_price == blank
assign variant_compare_at_price = variant.price
endif
endif
%}
{%- if variant.product.metafields.inventory.ShappifyHidden == 'true' -%}{%- continue -%}{%- endif -%}
{%- assign collection_handles = variant.product.collections | map: 'handle' -%}
{% if variant.product.id != skip_product.id %}
<div class="product-wrap">
<div class="product-image__wrapper">
<div class="image__container product__imageContainer">
<a href="{{ variant.url | within: collection }}">
{% comment %} {% if settings.stickers_enabled == true %}
{%
render 'product-thumbnail__sticker',
product: product,
context: 'product',
collection_handles: collection_handles
%}
{% endif %}{% endcomment %}
{% comment %} Primary image {% endcomment %}
{%
render 'image-element',
image: variant.featured_image,
alt: alt_text,
object_fit: align_height,
max_height: height
%}
</a>
</div>
{% if hover_enabled or settings.enable_quickshop %}
<a href="{{ variant.url | within: collection }}">
<div class="thumbnail-overlay__container">
{% if hover_enabled %}
<div class="quick-shop__info animated fadeInDown">
<div class="thumbnail-overlay">
<div class="info text-align-{{ settings.thumbnail_text_alignment }}">
<div class="product-thumbnail">
{% if settings.display_vendor %}
<span class="product-thumbnail__vendor">{{ variant.product.vendor }}</span>
{% endif %}
{% if hover_enabled %}
<span class="product-thumbnail__title">{{ variant.product.title }} - {{ variant.title }}</span>
{% else %}
<a href="{{ variant.url | within: collection }}" class="product-thumbnail__title">{{ variant.product.title }} - {{ variant.title }}</a>
{% endif %}
{% if collection_handles contains 'coming-soon' %}
{% if settings.stickers_enabled == false %}
{{ 'collections.general.coming_soon' | t }}
{% endif %}
{% else %}
<span class="product-thumbnail__price price {% if product_compare_at_price_max > product_price %}sale{% endif %}">
{% if variant_price > 0 %}
<span class="money">
{%
render 'price-element',
price: variant_price
%}
</span>
{% else %}
{{ settings.free_price_text }}
{% endif %}
</span>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}
{% if settings.enable_quickshop %}
{%
render 'product-thumbnail__quick-shop-button',
product: variant.product
%}
{% endif %}
{% if hover_enabled %}
{% if settings.enable_shopify_collection_badges %}
<span class="shopify-product-reviews-badge" data-id="{{ product.id }}"></span>
{% endif %}
{% endif %}
</div>
</a>
{% endif %}
</div>
{% if hover_enabled == false %}
<div class="thumbnail__caption text-align-{{ settings.thumbnail_text_alignment }}">
<div class="product-thumbnail">
{% if settings.display_vendor %}
<span class="product-thumbnail__vendor">{{ variant.product.vendor }}</span>
{% endif %}
{% if hover_enabled %}
<span class="product-thumbnail__title">{{ variant.product.title }} - {{ variant.title }}</span>
{% else %}
<a href="{{ variant.url | within: collection }}" class="product-thumbnail__title">{{ variant.product.title }} - {{ variant.title }}</a>
{% endif %}
{% if collection_handles contains 'coming-soon' %}
{% if settings.stickers_enabled == false %}
{{ 'collections.general.coming_soon' | t }}
{% endif %}
{% else %}
<span class="product-thumbnail__price price {% if product.compare_at_price_max > product.price %}sale{% endif %}">
{% if variant.price > 0 %}
<span class="money">
{%
render 'price-element',
price: variant.price
%}
</span>
{% else %}
{{ settings.free_price_text }}
{% endif %}
</span>
{% endif %}
</div>
</div>
{% endif %}
</div>
{% endif %}