{% liquid assign current_variant = product.selected_or_first_available_variant assign main_image = current_variant.image | default: product.featured_image 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 current_variant.title != 'Default Title' assign subtitle = current_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 assign badge_best = false 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 endfor assign excerpt = product.metafields.custom.descripcion_corta.value | default: product.metafields.custom.descripcion_corta if excerpt == blank assign excerpt = product.metafields.custom.short_description.value | default: product.metafields.custom.excerpt.value endif assign excerpt_from_description = false if excerpt == blank and product.description != blank assign excerpt_from_description = true assign excerpt_parts = product.description | replace: '

', '[[br]]' | replace: '', '[[br]]' | replace: '', '[[br]]' | replace: '', '[[br]]' | replace: '', '[[br]]' | replace: '', '[[br]]' | replace: '', '[[br]]' | replace: '', '[[br]]' | replace: '
', '[[br]]' | replace: '
', '[[br]]' | replace: '
', '[[br]]' | strip_html | split: '[[br]]' comment First paragraph: the first

of the description (falls back to the first text block). endcomment assign excerpt = '' if product.description contains '

' assign excerpt = product.description | split: '

' | first | split: '' | slice: 1, 999 | join: '>' | strip_html | strip endif if excerpt == blank for part in excerpt_parts assign part_text = part | strip if part_text != blank assign excerpt = part_text break endif endfor endif assign excerpt_count = 0 for part in excerpt_parts assign part_text = part | strip if part_text != blank assign excerpt_count = excerpt_count | plus: 1 endif endfor assign excerpt_has_more = false if excerpt_count > 1 assign excerpt_has_more = true endif endif assign how_field = product.metafields.custom.como_aplicarlo if how_field == blank assign how_field = product.metafields.custom.how_to endif if how_field == blank assign how_field = product.metafields.custom.modo_de_uso endif assign ingredients_field = product.metafields.custom.ingredientes if ingredients_field == blank assign ingredients_field = product.metafields.custom.ingredients endif assign payments_field = product.metafields.custom.metodos_de_pago if payments_field == blank assign payments_field = product.metafields.custom.payment_methods endif assign before_source = product.metafields.custom.antes.value | default: product.metafields.custom.before.value | default: product.metafields.custom.imagen_antes.value assign after_source = product.metafields.custom.despues.value | default: product.metafields.custom.after.value | default: product.metafields.custom.imagen_despues.value assign compare_pair = product.metafields.custom.antes_despues.value | default: product.metafields.custom.before_after.value if before_source == blank and compare_pair != blank assign before_source = compare_pair.first assign after_source = compare_pair.last endif assign before_image = blank if before_source.preview_image != blank assign before_image = before_source.preview_image elsif before_source.width != blank assign before_image = before_source endif assign after_image = blank if after_source.preview_image != blank assign after_image = after_source.preview_image elsif after_source.width != blank assign after_image = after_source endif assign show_compare = false if before_image != blank and after_image != blank assign show_compare = true endif assign before_alt = 'product_page.before' | t assign after_alt = 'product_page.after' | t assign show_sale = false if current_variant.compare_at_price > current_variant.price assign show_sale = true 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 | plus: 0 endif assign routine_products = product.metafields.custom.rutina.value | default: product.metafields.custom.completa_tu_rutina.value | default: product.metafields.custom.routine.value assign also_products = product.metafields.custom.llevate.value | default: product.metafields.custom.llevate_tambien.value | default: product.metafields.custom.tambien.value assign review_items = product.metafields.custom.resenas.value | default: product.metafields.custom.reviews.value assign review_count = 0 if review_items != blank assign review_count = review_items.size endif assign routine_count = 0 assign routine_ids = '|' if routine_products != blank for item in routine_products if item.id != blank and item.id != product.id assign routine_count = routine_count | plus: 1 assign routine_ids = routine_ids | append: item.id | append: '|' endif endfor endif assign also_count = 0 if also_products != blank for item in also_products assign item_token = '|' | append: item.id | append: '|' if item.id != blank and item.id != product.id unless routine_ids contains item_token assign also_count = also_count | plus: 1 endunless endif endfor endif assign show_reviews = false if rating_count > 0 or review_count > 0 assign show_reviews = true endif comment Hide the reviews module (and the stars under the title) when the average rating is below 3.5. endcomment assign reviews_min_rating = section.settings.reviews_min_rating | default: 3.5 | times: 1.0 assign rating_average = product.metafields.reviews.rating.value.rating | default: 0 | times: 1.0 assign low_rating = false if rating_count > 0 and rating_average < reviews_min_rating assign low_rating = true assign show_reviews = false endif assign review_pages = review_count | plus: 2 | divided_by: 3 assign main_alt = main_image.alt | default: product.title %}
{% if badge_best or skin_label != blank %}
{% if badge_best %} {{ 'bestsellers.badge' | t }} {% endif %} {% if skin_label != blank %} {{ skin_label | escape }} {% endif %}
{% endif %}

{{ product.title | escape }}

{% if subtitle != blank %}

{{ subtitle | escape }}

{% endif %} {% if rating_count > 0 and low_rating == false %}

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

{% endif %}

{{ current_variant.price | money_without_trailing_zeros }} {% if show_sale %}{{ current_variant.compare_at_price | money_without_trailing_zeros }}{% endif %}

{% if excerpt != blank %} {% if excerpt_from_description %}

{{ excerpt | escape }}

{%- if excerpt_has_more -%} {%- endif -%}
{% else %}

{{ excerpt | escape }}

{% endif %} {% endif %} {% form 'product', product, id: 'product-form', class: 'product__form' %} {% unless product.has_only_default_variant %}

{{ 'product_page.options' | t: option: current_variant.title }}

{% for variant in product.variants %} {% liquid assign variant_image = variant.image if variant_image == blank and variant.featured_media assign variant_image = variant.featured_media.preview_image endif if variant_image == blank assign variant_image = product.featured_image endif assign variant_sale = false if variant.compare_at_price > variant.price assign variant_sale = true endif %} {% endfor %}
{% endunless %}
  • {{ 'icon-marquee-shipping.svg' | inline_asset_content }} {{ 'product_page.shipping' | t }}
  • {{ 'icon-marquee-card.svg' | inline_asset_content }} {{ 'product_page.payment' | t }} Visa Mastercard American Express PayPal {{ 'apple_pay' | payment_type_svg_tag: class: 'h-6 w-auto max-w-none shrink-0' }} {{ 'google_pay' | payment_type_svg_tag: class: 'h-6 w-auto max-w-none shrink-0' }}
  • {{ 'icon-marquee-wallet.svg' | inline_asset_content }} {{ 'product_page.installments_with' | t }} Mercado Pago Kueski Pay Aplazo
  • {{ 'icon-marquee-guarantee.svg' | inline_asset_content }} {{ 'product_page.guarantee' | t }}
{% endform %} {% if additional_checkout_buttons %}

{{ 'product_page.express' | t }}

{{ content_for_additional_checkout_buttons }}
{% endif %} {% liquid assign sticky_image = current_variant.image if sticky_image == blank and current_variant.featured_media assign sticky_image = current_variant.featured_media.preview_image endif if sticky_image == blank assign sticky_image = product.featured_image endif %}
{% if sticky_image %} {{ sticky_image | image_url: width: 160 | image_tag: class: 'product-sticky__image', alt: '', widths: '80, 160', sizes: '48px', loading: 'lazy', data-sticky-image: 'true' }} {% endif %}

{{ product.title | escape }}

{{ current_variant.price | money_without_trailing_zeros }}

{% if product.description != blank %}
{{ 'product_page.description' | t }}
{{ product.description }}
{% endif %} {% if how_field != blank %}
{{ 'product_page.how_to' | t }}
{{ how_field | metafield_tag }}
{% endif %} {% if ingredients_field != blank %}
{{ 'product_page.ingredients' | t }}
{{ ingredients_field | metafield_tag }}
{% endif %}
{{ 'product_page.payments' | t }}
{% if payments_field != blank %} {{ payments_field | metafield_tag }} {% else %}

{{ 'product_page.payments_text' | t }}

{% endif %}

{{ 'product_page.routine' | t }}

{% if routine_products != blank %} {% assign routine_shown = 0 %} {% for item in routine_products %} {% if routine_shown < 2 and item.id != blank and item.id != product.id %} {% assign routine_key = 'routine-' | append: item.id %} {% render 'collection-card', product: item, form_suffix: routine_key %} {% assign routine_shown = routine_shown | plus: 1 %} {% endif %} {% endfor %} {% endif %}
{% if show_compare %}
{{ before_image | image_url: width: 1400 | image_tag: alt: before_alt, loading: 'lazy', widths: '600, 1000, 1400', sizes: '(min-width: 1120px) 45vw, 50vw' }} {{ 'product_page.before' | t }}
{{ after_image | image_url: width: 1400 | image_tag: alt: after_alt, loading: 'lazy', widths: '600, 1000, 1400', sizes: '(min-width: 1120px) 45vw, 50vw' }} {{ 'product_page.after' | t }}
{% endif %}

{{ 'product_page.also' | t }}

{% if also_products != blank %} {% assign also_shown = 0 %} {% for item in also_products %} {% assign item_token = '|' | append: item.id | append: '|' %} {% if also_shown < 4 and item.id != blank and item.id != product.id %} {% unless routine_ids contains item_token %} {% assign also_key = 'also-' | append: item.id %} {% render 'collection-card', product: item, form_suffix: also_key, badge_mode: 'collection' %} {% assign also_shown = also_shown | plus: 1 %} {% endunless %} {% endif %} {% endfor %} {% endif %}
{% if show_reviews %} {% assign rating_exact = product.metafields.reviews.rating.value.rating | default: rating_value | round: 2 %} {% assign rating_text = rating_exact | append: '' %} {% unless rating_text contains '.' %} {% assign rating_text = rating_text | append: '.00' %} {% else %} {% assign rating_decimals = rating_text | split: '.' | last %} {% if rating_decimals.size == 1 %} {% assign rating_text = rating_text | append: '0' %} {% endif %} {% endunless %}

{{ 'product_page.reviews' | t }}

{% if rating_count > 0 %}

{{ 'product_page.rating_of' | t: rating: rating_text }}

{{ 'product_page.based_on' | t: count: rating_count }}

{% endif %}
{{ 'product_page.review_rating' | t }} {% for star in (1..5) %} {% endfor %}
{% endif %}
{% javascript %} (() => { if (window.__seasonProduct) return; window.__seasonProduct = true; const wishlistKey = 'seasons-wishlist'; const readList = (key) => { try { const stored = JSON.parse(window.localStorage.getItem(key)); return Array.isArray(stored) ? stored.map(String) : []; } catch (error) { return []; } }; 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 writeWishlist = (items) => { window.localStorage.setItem(wishlistKey, JSON.stringify(items)); document.dispatchEvent(new CustomEvent('seasons:wishlist')); }; const root = document.querySelector('[data-product-page]'); if (!root) return; const handle = root.dataset.productHandle; if (handle) { const handles = [handle].concat(readList('seasons-recent').filter((item) => item !== handle)).slice(0, 8); window.localStorage.setItem('seasons-recent', JSON.stringify(handles)); } const applyWish = () => { const saved = readWishlist().map((item) => item.id); root.querySelectorAll('[data-product-wish], [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); }); }; applyWish(); document.addEventListener('seasons:wishlist', applyWish); root.querySelectorAll('.product__accordion').forEach((details) => { details.addEventListener('toggle', () => { if (!details.open) return; root.querySelectorAll('.product__accordion[open]').forEach((other) => { if (other !== details) other.open = false; }); }); }); const thumbs = root.querySelector('[data-product-thumbs]'); const lightbox = root.querySelector('[data-gallery-lightbox]'); const lightboxImage = lightbox ? lightbox.querySelector('[data-gallery-image]') : null; const gallerySlides = () => { const seen = new Set(); const slides = []; root.querySelectorAll('[data-gallery-open]').forEach((button) => { const src = button.getAttribute('data-full'); if (!src || seen.has(src)) return; seen.add(src); const image = button.querySelector('img'); slides.push({ src, alt: image ? image.alt : '' }); }); return slides; }; let slides = []; let slideIndex = 0; const showSlide = (next) => { if (!lightbox || !lightboxImage || !slides.length) return; slideIndex = (next + slides.length) % slides.length; const slide = slides[slideIndex]; lightboxImage.src = slide.src; lightboxImage.alt = slide.alt; const count = lightbox.querySelector('[data-gallery-count]'); const multiple = slides.length > 1; if (count) { count.hidden = !multiple; const template = count.getAttribute('data-template') || ''; count.textContent = template.replace('__C__', String(slideIndex + 1)).replace('__T__', String(slides.length)); } lightbox.querySelectorAll('[data-gallery-prev], [data-gallery-next]').forEach((button) => { button.hidden = !multiple; }); }; const openLightbox = (button) => { if (!button || !lightbox || !lightboxImage) return; const full = button.getAttribute('data-full'); if (!full) return; slides = gallerySlides(); const start = Math.max(0, slides.findIndex((slide) => slide.src === full)); showSlide(start); if (!lightbox.open) lightbox.showModal(); }; if (thumbs) { let pointerId = null; let startX = 0; let startScroll = 0; let dragged = false; let pending = null; thumbs.addEventListener('pointerdown', (event) => { if (event.pointerType === 'mouse' && event.button !== 0) return; pointerId = event.pointerId; startX = event.clientX; startScroll = thumbs.scrollLeft; dragged = false; pending = event.target.closest('[data-gallery-open]'); }); thumbs.addEventListener('pointermove', (event) => { if (event.pointerId !== pointerId) return; const delta = event.clientX - startX; if (Math.abs(delta) > 8) { dragged = true; if (!thumbs.classList.contains('is-dragging')) { thumbs.classList.add('is-dragging'); thumbs.setPointerCapture(pointerId); } thumbs.scrollLeft = startScroll - delta; } }); const endDrag = (event) => { if (event.pointerId !== pointerId) return; const button = pending; pointerId = null; pending = null; thumbs.classList.remove('is-dragging'); if (event.type === 'pointercancel' || dragged) return; openLightbox(button); }; thumbs.addEventListener('pointerup', endDrag); thumbs.addEventListener('pointercancel', endDrag); thumbs.addEventListener('dragstart', (event) => event.preventDefault()); const progress = root.querySelector('[data-gallery-progress]'); const mark = progress ? progress.querySelector('span') : null; const syncProgress = () => { if (!mark || !thumbs.clientWidth) return; const slides = thumbs.children.length; const index = Math.max(0, Math.min(slides - 1, Math.round(thumbs.scrollLeft / thumbs.clientWidth))); mark.style.transform = 'translateX(' + (index * 100) + '%)'; if (progress) progress.setAttribute('aria-valuenow', String(index + 1)); }; thumbs.addEventListener('scroll', syncProgress, { passive: true }); window.addEventListener('resize', syncProgress); syncProgress(); thumbs.addEventListener('click', (event) => { if (dragged) return; openLightbox(event.target.closest('[data-gallery-open]')); }); } const mainImage = root.querySelector('.product__main[data-gallery-open]'); if (mainImage) { mainImage.addEventListener('click', () => openLightbox(mainImage)); } if (lightbox && lightboxImage) { let swipeX = null; let swiped = false; lightbox.addEventListener('click', (event) => { if (event.target.closest('[data-gallery-close]')) { lightbox.close(); return; } if (event.target.closest('[data-gallery-prev]')) { showSlide(slideIndex - 1); return; } if (event.target.closest('[data-gallery-next]')) { showSlide(slideIndex + 1); return; } if (swiped) { swiped = false; return; } const rect = lightbox.getBoundingClientRect(); const inside = event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom; if (!inside) lightbox.close(); }); lightbox.addEventListener('keydown', (event) => { if (event.key === 'ArrowLeft') { event.preventDefault(); showSlide(slideIndex - 1); } if (event.key === 'ArrowRight') { event.preventDefault(); showSlide(slideIndex + 1); } }); lightbox.addEventListener('pointerdown', (event) => { if (event.target !== lightboxImage) return; swipeX = event.clientX; swiped = false; }); lightbox.addEventListener('pointerup', (event) => { if (swipeX == null || event.target !== lightboxImage) return; const delta = event.clientX - swipeX; swipeX = null; if (Math.abs(delta) < 40) return; swiped = true; showSlide(slideIndex + (delta < 0 ? 1 : -1)); }); lightbox.addEventListener('close', () => { lightboxImage.removeAttribute('src'); }); } const form = root.querySelector('.product__form'); const qtyInput = root.querySelector('[data-qty-input]'); root.addEventListener('click', (event) => { const wishCard = event.target.closest('[data-wishlist]'); if (wishCard && root.contains(wishCard)) { const id = String(wishCard.dataset.productId || ''); const cardHandle = String(wishCard.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: cardHandle }); writeWishlist(next); applyWish(); return; } const wish = event.target.closest('[data-product-wish]'); if (wish && root.contains(wish)) { 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 }); writeWishlist(next); applyWish(); return; } const qtyButton = event.target.closest('[data-qty]'); if (qtyButton && qtyInput && root.contains(qtyButton)) { const current = Math.max(1, Number(qtyInput.value) || 1); qtyInput.value = String(qtyButton.dataset.qty === 'down' ? Math.max(1, current - 1) : current + 1); return; } const option = event.target.closest('[data-variant]'); if (!option || !root.contains(option)) return; root.querySelectorAll('[data-variant]').forEach((node) => { node.classList.toggle('is-selected', node === option); }); const idInput = form?.querySelector('[name="id"]'); if (idInput) { idInput.value = option.dataset.id || idInput.value; idInput.dispatchEvent(new Event('change', { bubbles: true })); } const price = root.querySelector('[data-price]'); if (price) price.textContent = option.dataset.price || ''; const compare = root.querySelector('[data-compare]'); if (compare) { if (option.dataset.compare) { compare.hidden = false; compare.textContent = option.dataset.compare; } else { compare.hidden = true; compare.textContent = ''; } } const optionLabel = root.querySelector('[data-option-template]'); if (optionLabel) { const template = optionLabel.dataset.optionTemplate || ''; optionLabel.textContent = template.replace('__OPTION__', option.dataset.title || ''); } const available = option.dataset.available === 'true'; const addButton = root.querySelector('[data-add]'); const buyButton = root.querySelector('[data-buy]'); const stickyAdd = root.querySelector('[data-sticky-add]'); const stickyPrice = root.querySelector('[data-sticky-price]'); if (addButton) { addButton.disabled = !available; addButton.textContent = available ? addButton.dataset.label || addButton.textContent : addButton.dataset.soldOut || addButton.textContent; } if (stickyAdd) { stickyAdd.disabled = !available; stickyAdd.textContent = available ? stickyAdd.dataset.label || stickyAdd.textContent : stickyAdd.dataset.soldOut || stickyAdd.textContent; } if (stickyPrice) stickyPrice.textContent = option.dataset.price || ''; if (buyButton) buyButton.disabled = !available; const wallets = root.querySelector('[data-wallets]'); if (wallets) wallets.hidden = !available; const main = root.querySelector('[data-main-image]'); if (main && option.dataset.image) { main.removeAttribute('srcset'); main.src = option.dataset.image; const mainButton = main.closest('[data-gallery-open]'); if (mainButton) mainButton.setAttribute('data-full', option.dataset.image); const twin = root.querySelector('.product__thumb--main[data-gallery-open]'); if (twin) twin.setAttribute('data-full', option.dataset.image); } const stickyImage = root.querySelector('[data-sticky-image]'); if (stickyImage && option.dataset.image) { stickyImage.removeAttribute('srcset'); stickyImage.src = option.dataset.image; } }); root.addEventListener('submit', async (event) => { const cardForm = event.target; if (!(cardForm instanceof HTMLFormElement) || !cardForm.hasAttribute('data-collection-card') || !root.contains(cardForm)) return; event.preventDefault(); const button = event.submitter instanceof HTMLButtonElement ? event.submitter : cardForm.querySelector('[type="submit"]'); const variantId = cardForm.querySelector('[name="id"]')?.value; if (!button || button.disabled || !variantId) return; const buttons = [...cardForm.querySelectorAll('button')]; buttons.forEach((item) => { item.disabled = true; }); const buyNow = button.hasAttribute('data-buy'); try { const addResponse = await fetch(`${cardForm.action}.js`, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ id: Number(variantId), quantity: 1 }), }); if (!addResponse.ok) { cardForm.submit(); return; } if (buyNow) { const base = (root.dataset.root || '/').replace(/\/?$/, '/'); window.location.href = `${base}checkout`; return; } document.dispatchEvent(new CustomEvent('season:cart:open')); } catch (error) { cardForm.submit(); } finally { if (!buyNow) { buttons.forEach((item) => { item.disabled = false; }); } } }); form?.addEventListener('submit', async (event) => { const submitter = event.submitter; if (!(submitter instanceof HTMLButtonElement) || !submitter.hasAttribute('data-buy')) return; event.preventDefault(); if (submitter.disabled) return; const variantId = form.querySelector('[name="id"]')?.value; const quantity = Math.max(1, Number(qtyInput?.value) || 1); if (!variantId) return; submitter.disabled = true; try { const response = await fetch(`${form.action}.js`, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ id: Number(variantId), quantity }), }); if (!response.ok) { form.submit(); return; } window.location.href = `${window.Shopify?.routes?.root || '/'}checkout`; } catch (error) { form.submit(); } }); const usedHandles = () => { return new Set( [...root.querySelectorAll('.collection-card__title')] .map((link) => { const href = link.getAttribute('href') || ''; const parts = href.split('/').filter(Boolean); return parts[parts.length - 1] || ''; }) .filter(Boolean) ); }; const fillRecs = async (block) => { if (!block || block.dataset.filled === 'true') return; const list = block.querySelector('[data-recs-list]'); const productId = root.dataset.productId; if (!list || !productId) return; const base = (root.dataset.root || '/').replace(/\/?$/, '/'); const limit = Number(block.dataset.limit) || 4; try { const response = await fetch( `${base}recommendations/products.json?product_id=${productId}&limit=${limit + 2}&intent=${block.dataset.recs || 'related'}` ); if (!response.ok) throw new Error('recommendations'); const data = await response.json(); const skip = usedHandles(); skip.add(root.dataset.productHandle || ''); const products = (data.products || []) .filter((item) => item && item.handle && !skip.has(item.handle)) .slice(0, limit); if (!products.length) { block.hidden = true; return; } const cards = await Promise.all( products.map(async (item) => { const html = await fetch(`${base}products/${item.handle}?view=card`).then((result) => result.text()); const wrapper = document.createElement('div'); wrapper.innerHTML = html; return wrapper.firstElementChild; }) ); const nodes = cards.filter(Boolean); if (!nodes.length) { block.hidden = true; return; } list.replaceChildren(...nodes); block.hidden = false; block.dataset.filled = 'true'; applyWish(); } catch (error) { block.hidden = true; } }; (async () => { const blocks = [...root.querySelectorAll('[data-product-block]')]; for (const block of blocks) { await fillRecs(block); } })(); const reviewsRoot = root.querySelector('[data-product-reviews]'); if (reviewsRoot) { const list = reviewsRoot.querySelector('[data-review-list]'); const more = reviewsRoot.querySelector('[data-review-more]'); const writeButton = reviewsRoot.querySelector('[data-write-review]'); const writeForm = reviewsRoot.querySelector('#product-review-form'); const cache = new Map(); let productExternalId = reviewsRoot.dataset.productId; let currentPage = 1; let loading = false; const reviewsShop = reviewsRoot.dataset.reviewsShop || reviewsRoot.dataset.shop; const starPath = 'M7 1.2l1.45 3.22 3.5.4-2.62 2.38.74 3.46L7 8.95 3.93 10.66l.74-3.46L2.05 4.82l3.5-.4L7 1.2z'; const plainText = (html) => { const parsed = new DOMParser().parseFromString(html || '', 'text/html'); return (parsed.body.textContent || '').trim(); }; const avatarIcon = ''; const pictureUrl = (pic) => { if (!pic) return ''; if (typeof pic === 'string') return pic; return (pic.urls && (pic.urls.compact || pic.urls.small || pic.urls.original)) || pic.compact || pic.small || pic.original || ''; }; const fallbackProductImage = reviewsRoot.dataset.productImage || ''; const renderReviews = (reviews, append, data) => { if (!append) list.replaceChildren(); reviews.forEach((review) => { const rating = Math.max(1, Math.min(5, Math.round(Number(review.rating) || 0))); const article = document.createElement('article'); article.className = 'product__review'; article.dataset.review = ''; const stars = document.createElement('span'); stars.className = 'product__stars'; stars.setAttribute('aria-label', rating + ' de 5'); for (let star = 1; star <= 5; star += 1) { const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); icon.setAttribute('class', 'product__star' + (star > rating ? ' is-off' : '')); icon.setAttribute('width', '16'); icon.setAttribute('height', '16'); icon.setAttribute('viewBox', '0 0 14 14'); icon.setAttribute('aria-hidden', 'true'); const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); path.setAttribute('d', starPath); path.setAttribute('fill', 'currentColor'); icon.append(path); stars.append(icon); } const person = document.createElement('div'); person.className = 'product__review-person'; const avatar = document.createElement('span'); avatar.className = 'product__avatar'; avatar.setAttribute('aria-hidden', 'true'); const avatarUrl = review.avatar_image_url || (review.gravatar_hash ? 'https://www.gravatar.com/avatar/' + review.gravatar_hash + '?s=96&d=404' : ''); if (avatarUrl) { const avatarImg = document.createElement('img'); avatarImg.className = 'product__avatar-img'; avatarImg.src = avatarUrl; avatarImg.alt = ''; avatarImg.width = 48; avatarImg.height = 48; avatarImg.loading = 'lazy'; avatarImg.decoding = 'async'; avatarImg.addEventListener('error', () => { avatar.innerHTML = avatarIcon; }, { once: true }); avatar.append(avatarImg); } else { avatar.innerHTML = avatarIcon; } const name = document.createElement('p'); name.className = 'product__review-name'; name.textContent = review.reviewer_name || 'Cliente'; person.append(avatar, name); const text = document.createElement('p'); text.className = 'product__review-text'; const body = plainText(review.body_html); text.textContent = body || review.title || ''; article.append(stars, person, text); const photos = (review.pictures_urls || []).map(pictureUrl).filter(Boolean); if (photos.length) { const gallery = document.createElement('div'); gallery.className = 'product__review-photos'; photos.slice(0, 4).forEach((src) => { const img = document.createElement('img'); img.src = src; img.alt = 'Foto de ' + (review.reviewer_name || 'cliente'); img.width = 64; img.height = 64; img.loading = 'lazy'; img.decoding = 'async'; gallery.append(img); }); article.append(gallery); } const productImage = review.product_variant_image_url || (data && data.image_url) || fallbackProductImage; if (productImage) { const productRow = document.createElement('div'); productRow.className = 'product__review-product'; const thumb = document.createElement('img'); thumb.src = productImage + (productImage.includes('?') ? '&' : '?') + 'width=96'; thumb.alt = ''; thumb.width = 40; thumb.height = 40; thumb.loading = 'lazy'; thumb.decoding = 'async'; const label = document.createElement('span'); label.textContent = review.product_title || (data && data.product_name) || ''; productRow.append(thumb, label); article.append(productRow); } list.append(article); }); }; const updateMore = (page, total) => { currentPage = page; if (!more) return; more.hidden = page >= total; }; const loadPage = async (page, append) => { if (loading || !productExternalId || !reviewsShop) return; loading = true; if (more) more.disabled = true; try { if (!cache.has(page)) { const url = new URL('https://judge.me/reviews/reviews_for_widget'); url.searchParams.set('url', reviewsShop); url.searchParams.set('shop_domain', reviewsShop); url.searchParams.set('platform', 'shopify'); url.searchParams.set('page', String(page)); url.searchParams.set('per_page', '3'); url.searchParams.set('product_id', String(productExternalId)); const response = await fetch(url); if (!response.ok) return; cache.set(page, await response.json()); } const data = cache.get(page); if (page === 1 && Number(data.number_of_reviews) > 0 && Number(data.average_rating) < (Number(reviewsRoot.dataset.minRating) || 0)) { reviewsRoot.hidden = true; return; } renderReviews(data.reviews || [], append, data); updateMore(page, data.pagination ? data.pagination.total_pages : 1); } finally { loading = false; if (more) more.disabled = false; } }; const resolveProduct = async () => { if (!reviewsShop || reviewsShop === reviewsRoot.dataset.shop) return; const storefront = (reviewsRoot.dataset.reviewsStorefront || '').replace(/\/$/, ''); const handle = reviewsRoot.dataset.productHandle; if (!storefront || !handle) return; const response = await fetch(storefront + '/products/' + handle + '.js'); if (!response.ok) return; const product = await response.json(); if (product && product.id) productExternalId = String(product.id); }; if (more) { more.addEventListener('click', () => { loadPage(currentPage + 1, true); }); } resolveProduct().then(() => loadPage(1, false)).catch(() => {}); if (writeButton && writeForm) { const openForm = (open) => { writeForm.classList.toggle('is-open', open); writeButton.setAttribute('aria-expanded', open ? 'true' : 'false'); }; writeButton.addEventListener('click', () => { openForm(!writeForm.classList.contains('is-open')); }); writeForm.addEventListener('submit', async (event) => { event.preventDefault(); const success = writeForm.querySelector('.product__write-success'); const error = writeForm.querySelector('.product__write-error'); if (success) success.hidden = true; if (error) error.hidden = true; const payload = new URLSearchParams(); payload.set('shop_domain', reviewsShop); payload.set('platform', 'shopify'); payload.set('id', String(productExternalId || '')); payload.set('name', writeForm.reviewer_name.value); payload.set('email', writeForm.reviewer_email.value); payload.set('rating', (writeForm.querySelector('input[name="score"]:checked') || {}).value || '5'); payload.set('body', writeForm.review_body.value); try { const response = await fetch('https://api.judge.me/api/v1/reviews', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: payload, }); if (!response.ok) throw new Error('review'); if (success) { success.hidden = false; success.textContent = writeForm.dataset.sent || ''; } writeForm.reset(); } catch (submitError) { if (error) { error.hidden = false; error.textContent = writeForm.dataset.error || ''; } } }); } } })(); {% endjavascript %} {% schema %} { "name": "t:product_page.name", "settings": [ { "type": "paragraph", "content": "t:product_page.metafields" }, { "type": "range", "id": "reviews_min_rating", "label": "Calificación mínima para mostrar reseñas", "info": "Si el promedio del producto es menor, se ocultan las reseñas y las estrellas. 0 = mostrar siempre.", "min": 0, "max": 5, "step": 0.1, "default": 3.5 }, { "type": "text", "id": "reviews_shop", "label": "t:product_page.reviews_shop", "info": "t:product_page.reviews_shop_info", "default": "seasons-world.myshopify.com" }, { "type": "text", "id": "reviews_storefront", "label": "t:product_page.reviews_storefront", "info": "t:product_page.reviews_storefront_info", "default": "https://www.seasonsmexico.com" } ], "disabled_on": { "groups": [ "header", "footer" ] } } {% endschema %}