{% doc %} Renders a collection product card. Hover shows the second image plus add to cart and buy now. @param {product} product - Product to display @param {string} [form_suffix] - Keeps the product form id unique @param {string} [badge_mode] - `tags` shows the skin label, `collection` shows the category collection, `none` hides badges @example {% render 'collection-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 badge_mode = badge_mode | default: 'tags' %} {% if badge_mode == 'collection' %} {% capture collection_label %} {% render 'product-collection-label', product: product %} {% endcapture %} {% endif %} {% liquid assign collection_label = collection_label | strip assign skin_label = blank assign badge_best = false assign badge_recommended = false if badge_mode != 'none' if badge_mode == 'tags' 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 endif for tag in product.tags assign tag_label = tag | downcase if tag_label contains 'vendido' or tag_label contains 'bestseller' assign badge_best = true endif if tag_label contains 'recomend' assign badge_recommended = true endif if badge_mode == 'tags' and skin_label == blank and tag_label contains 'piel' assign skin_label = tag endif endfor 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 show_compare = false if variant.compare_at_price > variant.price assign show_compare = true endif assign form_id = 'collection-card-' | append: product.id if form_suffix != blank assign form_id = form_id | append: '-' | append: form_suffix endif %}
{% if card_image %} {{ card_image | image_url: width: 900 | image_tag: alt: image_alt, widths: '186, 372, 560, 800', sizes: '(max-width: 767px) 46vw, 33vw', class: 'collection-card__image', loading: 'lazy' }} {% if hover_image != blank %} {{ hover_image | image_url: width: 900 | image_tag: alt: '', widths: '186, 372, 560, 800', sizes: '(max-width: 767px) 46vw, 33vw', class: 'collection-card__image collection-card__image--hover', loading: 'lazy' }} {% endif %} {% else %} {% endif %} {% if badge_mode != 'none' %}
{% if badge_best %} {{ 'bestsellers.badge' | t }} {% endif %} {% if badge_recommended %} {{ 'collection_page.recommended' | t }} {% endif %} {% if badge_mode == 'collection' and collection_label != blank %} {{ collection_label | escape }} {% elsif badge_mode == 'tags' and skin_label != blank %} {{ skin_label | escape }} {% endif %}
{% endif %}
{{ product.title | escape }} {% if subtitle != blank %}

{{ subtitle | escape }}

{% endif %} {% if rating_count > 0 %}

{{ 'bestsellers.reviews' | t: count: rating_count }}

{% endif %}

{{ variant.price | money_without_trailing_zeros }} {% if show_compare %} {{ variant.compare_at_price | money_without_trailing_zeros }} {% endif %}

{% javascript %} (() => { if (window.__seasonCollectionCard) return; window.__seasonCollectionCard = true; const wishlistKey = 'seasons-wishlist'; const readWishlist = () => { try { const stored = JSON.parse(window.localStorage.getItem(wishlistKey)); if (!Array.isArray(stored)) return []; return stored.map((item) => { if (item && typeof item === 'object') return { id: String(item.id || ''), handle: String(item.handle || '') }; return { id: String(item), handle: '' }; }).filter((item) => item.id); } catch (error) { return []; } }; const applyWishlist = () => { const saved = readWishlist().map((item) => item.id); document.querySelectorAll('.collection-card [data-wishlist]').forEach((button) => { const active = saved.includes(String(button.dataset.productId)); button.classList.toggle('is-active', active); button.setAttribute('aria-pressed', active ? 'true' : 'false'); const label = active ? button.dataset.labelSaved : button.dataset.labelSave; if (label) button.setAttribute('aria-label', label); }); }; applyWishlist(); document.addEventListener('seasons:wishlist', applyWishlist); document.addEventListener('click', (event) => { const wish = event.target.closest('.collection-card [data-wishlist]'); if (!wish || wish.closest('[data-product-page]')) return; const id = String(wish.dataset.productId || ''); const handle = String(wish.dataset.productHandle || ''); if (!id) return; const saved = readWishlist(); const next = saved.some((item) => item.id === id) ? saved.filter((item) => item.id !== id) : saved.concat({ id, handle }); window.localStorage.setItem(wishlistKey, JSON.stringify(next)); document.dispatchEvent(new CustomEvent('seasons:wishlist')); applyWishlist(); }); document.addEventListener('submit', async (event) => { if (event.defaultPrevented) return; const form = event.target; if (!(form instanceof HTMLFormElement) || !form.hasAttribute('data-collection-card')) return; if (form.closest('[data-product-page]')) return; if (event.defaultPrevented) return; event.preventDefault(); const button = event.submitter instanceof HTMLButtonElement ? event.submitter : form.querySelector('[type="submit"]'); const variantId = form.querySelector('[name="id"]')?.value; if (!button || button.disabled || !variantId) return; const buttons = [...form.querySelectorAll('button')]; buttons.forEach((item) => { item.disabled = true; }); const buyNow = button.hasAttribute('data-buy'); try { const addResponse = await fetch(`${form.action}.js`, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ id: Number(variantId), quantity: 1 }), }); if (!addResponse.ok) { form.submit(); return; } if (buyNow) { window.location.href = `${window.Shopify?.routes?.root || '/'}checkout`; return; } document.dispatchEvent(new CustomEvent('season:cart:open')); } catch (error) { form.submit(); } finally { if (!buyNow) { buttons.forEach((item) => { item.disabled = false; }); } } }); })(); {% endjavascript %}