Files
season/snippets/bestsellers-card.liquid
2026-10-09 23:02:05 -06:00

186 lines
7.9 KiB
Plaintext

{% doc %}
Renders one product card for the best sellers slider.
@param {product} product - Product to display
@param {string} [form_suffix] - Suffix that keeps the add-to-cart form id unique
@example
{% render 'bestsellers-card', product: product, form_suffix: section.id %}
{% enddoc %}
{% liquid
assign variant = product.selected_or_first_available_variant
assign card_image = product.featured_image
assign hover_image = blank
for image in product.images offset: 1 limit: 1
assign hover_image = image
endfor
assign image_alt = card_image.alt | default: product.title
assign subtitle = product.metafields.custom.subtitulo.value | default: product.metafields.custom.subtitulo
if subtitle == blank
assign subtitle = product.metafields.custom.subtitle.value | default: product.metafields.custom.subtitle
endif
if subtitle == blank
assign subtitle = product.metafields.custom.presentacion.value | default: product.metafields.custom.presentacion
endif
if subtitle == blank and variant.title != 'Default Title'
assign subtitle = variant.title
endif
assign skin_label = product.metafields.custom.tipo_de_piel.value | default: product.metafields.custom.tipo_de_piel
if skin_label == blank
assign skin_label = product.metafields.custom.skin_type.value | default: product.metafields.custom.skin_type
endif
if skin_label == blank
assign skin_fallback = blank
for tag in product.tags
assign tag_label = tag | downcase
if tag_label contains 'piel'
if skin_fallback == blank
assign skin_fallback = tag
endif
if tag_label contains 'pieles' or tag_label contains 'piel '
assign skin_label = tag
break
endif
endif
endfor
if skin_label == blank
assign skin_label = skin_fallback
endif
endif
assign rating_value = 0
assign rating_count = 0
if product.metafields.reviews.rating.value != blank
assign rating_value = product.metafields.reviews.rating.value.rating | round
endif
if product.metafields.reviews.rating_count.value != blank
assign rating_count = product.metafields.reviews.rating_count.value
endif
assign compare_price = variant.compare_at_price
assign show_compare = false
if compare_price > variant.price
assign show_compare = true
endif
%}
<article class="bestsellers__card">
<div class="bestsellers__media">
<a class="bestsellers__media-link" href="{{ product.url }}">
{% if card_image %}
{{
card_image
| image_url: width: 800
| image_tag:
alt: image_alt,
widths: '245, 386, 490, 772',
sizes: '(max-width: 1024px) 245px, 386px',
class: 'bestsellers__image',
loading: 'lazy'
}}
{% if hover_image != blank %}
{{
hover_image
| image_url: width: 800
| image_tag:
alt: '',
widths: '245, 386, 490, 772',
sizes: '(max-width: 1024px) 245px, 386px',
class: 'bestsellers__image bestsellers__image--hover',
loading: 'lazy'
}}
{% endif %}
{% else %}
<span class="bestsellers__image bestsellers__image--empty" aria-hidden="true"></span>
{% endif %}
</a>
<div class="bestsellers__badges">
<span class="bestsellers__badge bestsellers__badge--best">{{ 'bestsellers.badge' | t }}</span>
{% if skin_label != blank %}
<span class="bestsellers__badge bestsellers__badge--skin">{{ skin_label | escape }}</span>
{% endif %}
</div>
<form class="bestsellers__actions bestsellers__form" action="{{ routes.cart_add_url }}" method="post">
<input type="hidden" name="id" value="{{ variant.id }}">
<input type="hidden" name="quantity" value="1">
<button
class="bestsellers__bag"
type="submit"
{% unless variant.available %}disabled{% endunless %}
aria-label="{{ 'bestsellers.add_to_cart' | t }}"
>
<img src="{{ 'testimonials-bag.svg' | asset_url }}" alt="" width="25" height="25"
loading="lazy"
decoding="async"
>
</button>
<button
class="bestsellers__buy"
type="submit"
data-buy
{% unless variant.available %}disabled{% endunless %}
>
{% if variant.available %}
{{ 'bestsellers.buy_now' | t }}
{% else %}
{{ 'bestsellers.sold_out' | t }}
{% endif %}
</button>
</form>
<button
class="bestsellers__wish"
type="button"
data-wishlist
data-product-id="{{ product.id }}"
data-product-handle="{{ product.handle }}"
aria-pressed="false"
aria-label="{{ 'bestsellers.save' | t: product: product.title }}"
data-label-save="{{ 'bestsellers.save' | t: product: product.title }}"
data-label-saved="{{ 'bestsellers.saved' | t: product: product.title }}"
>
<span class="bestsellers__wish-icon" aria-hidden="true">
<svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17.2324 3.90625C14.0625 3.90625 12.5 7.03125 12.5 7.03125C12.5 7.03125 10.9375 3.90625 7.76758 3.90625C5.19141 3.90625 3.15137 6.06152 3.125 8.6333C3.07129 13.9717 7.35986 17.7681 12.0605 20.9585C12.1901 21.0467 12.3433 21.0938 12.5 21.0938C12.6567 21.0938 12.8099 21.0467 12.9395 20.9585C17.6396 17.7681 21.9282 13.9717 21.875 8.6333C21.8486 6.06152 19.8086 3.90625 17.2324 3.90625Z" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
</button>
</div>
<div class="bestsellers__info">
<div class="bestsellers__copy">
<a class="bestsellers__title" href="{{ product.url }}">{{ product.title | escape }}</a>
{% if subtitle != blank %}
<p class="bestsellers__subtitle">{{ subtitle | escape }}</p>
{% endif %}
{% if rating_count > 0 %}
<div class="bestsellers__rating">
<div class="bestsellers__stars" aria-hidden="true">
{% for index in (1..5) %}
<span class="bestsellers__star{% if index > rating_value %} is-off{% endif %}">
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path d="M7.69531 9.39111C7.62954 9.39136 7.56536 9.37086 7.51191 9.33251L5 7.51142L2.48809 9.33251C2.43442 9.37144 2.36977 9.39228 2.30347 9.39204C2.23718 9.3918 2.17268 9.37048 2.1193 9.33117C2.06592 9.29186 2.02642 9.23659 2.00652 9.17335C1.98662 9.11011 1.98735 9.04218 2.00859 8.97939L2.98828 6.07763L0.449219 4.33642C0.394221 4.29874 0.352712 4.24447 0.330756 4.18153C0.3088 4.11858 0.307549 4.05027 0.327184 3.98656C0.34682 3.92285 0.386313 3.86709 0.439895 3.82743C0.493476 3.78777 0.558336 3.76628 0.625 3.7661H3.75742L4.70273 0.856925C4.7231 0.794117 4.76283 0.739373 4.81624 0.700546C4.86964 0.66172 4.93397 0.640807 5 0.640807C5.06603 0.640807 5.13036 0.66172 5.18376 0.700546C5.23717 0.739373 5.2769 0.794117 5.29727 0.856925L6.24258 3.76708H9.375C9.44175 3.76705 9.50675 3.78839 9.56049 3.82797C9.61423 3.86756 9.65389 3.92331 9.67365 3.98707C9.69341 4.05082 9.69223 4.11923 9.6703 4.18227C9.64837 4.24531 9.60682 4.29967 9.55176 4.33739L7.01172 6.07763L7.99082 8.97861C8.00668 9.02557 8.01115 9.07564 8.00384 9.12467C7.99653 9.17371 7.97766 9.2203 7.94879 9.2606C7.91992 9.3009 7.88188 9.33375 7.8378 9.35644C7.79373 9.37913 7.74489 9.39102 7.69531 9.39111Z" fill="black"/>
</svg>
</span>
{% endfor %}
</div>
<p class="bestsellers__reviews">{{ 'bestsellers.reviews' | t: count: rating_count }}</p>
</div>
{% endif %}
</div>
<div class="bestsellers__prices">
<span class="bestsellers__price">{{ variant.price | money_without_trailing_zeros }}</span>
{% if show_compare %}
<s class="bestsellers__compare">{{ compare_price | money_without_trailing_zeros }}</s>
{% endif %}
</div>
</div>
</article>