{% liquid assign product_collection = section.settings.collection if product_collection == blank assign product_collection = collections.all endif if section.settings.heading != blank assign heading = section.settings.heading else assign heading = 'bestsellers.heading' | t endif assign more_url = routes.all_products_collection_url assign feed_url = blank assign already_sorted = false if product_collection != blank assign more_url = product_collection.url | sort_by: 'best-selling' assign feed_url = more_url | append: '&view=bestsellers-data' if product_collection.default_sort_by == 'best-selling' assign already_sorted = true endif endif if section.settings.promo_link != blank assign promo_tag = 'a' else assign promo_tag = 'div' endif assign products_to_show = section.settings.products_to_show | default: 8 %}

{{ heading | escape }}

<{{ promo_tag }} class="bestsellers__promo" {% if promo_tag == 'a' %} href="{{ section.settings.promo_link }}" {% endif %} > {% if section.settings.promo_image != blank %} {{ section.settings.promo_image | image_url: width: 1400 | image_tag: alt: heading, widths: '372, 486, 744, 972', sizes: '(max-width: 1024px) calc(100vw - 30px), 486px', class: 'bestsellers__promo-image', loading: 'eager' }} {% else %} {{ heading | escape }} {% endif %}
{% if product_collection != blank and product_collection.products_count > 0 %} {% for product in product_collection.products limit: products_to_show %} {% render 'bestsellers-card', product: product, form_suffix: section.id %} {% endfor %} {% elsif request.design_mode %}

{{ 'bestsellers.empty' | t }}

{% endif %}
{% stylesheet %} .bestsellers { padding: 50px 0; color: #000; background: #fff; font-family: Archivo, sans-serif; } .bestsellers__header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; padding: 0 100px; } .bestsellers__heading { margin: 0; color: #000; font-family: "Roc Grotesk", Archivo, sans-serif; font-size: 30px; font-weight: 500; line-height: normal; text-transform: uppercase; } .bestsellers__tools { display: flex; flex-shrink: 0; align-items: center; gap: 10px; } .bestsellers__more { padding: 0 10px; color: #000; font-size: 16px; font-weight: 500; line-height: normal; text-decoration: none; } .bestsellers__arrows { display: flex; align-items: center; gap: 20px; } .bestsellers__arrow { display: grid; width: 30px; height: 30px; place-items: center; padding: 0; border: 0; border-radius: 60px; background: #9dd6c7; cursor: pointer; } .bestsellers__arrow:disabled { cursor: default; opacity: 0.35; } .bestsellers__arrow-icon { display: block; width: 20px; height: 20px; } .bestsellers__arrow--prev .bestsellers__arrow-icon { transform: rotate(-90deg); } .bestsellers__arrow--next .bestsellers__arrow-icon { transform: rotate(90deg); } .bestsellers__body { display: flex; align-items: flex-start; gap: 28px; } .bestsellers__promo { position: relative; display: block; flex: 0 0 486px; width: 486px; height: 550px; overflow: hidden; border-radius: 0 10px 10px 0; color: inherit; text-decoration: none; } .bestsellers__promo-image { display: block; width: 100%; height: 100%; object-fit: cover; } .bestsellers__slider { display: flex; min-width: 0; flex: 1 1 auto; flex-direction: column; align-self: stretch; } .bestsellers__progress { position: relative; height: 1px; margin-top: auto; background: #e6e6e6; } .bestsellers__progress-bar { position: absolute; top: 0; left: 0; height: 2px; background: #000; } .bestsellers__viewport { min-width: 0; min-height: 493px; flex: 1 1 auto; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; cursor: grab; } .bestsellers[data-feed]:not([data-sorted="true"]) .bestsellers__card { visibility: hidden; } .bestsellers__viewport::-webkit-scrollbar { display: none; } .bestsellers__viewport.is-dragging { cursor: grabbing; scroll-snap-type: none; } .bestsellers__track { display: flex; gap: 30px; width: max-content; padding-right: 100px; } .bestsellers__card { display: flex; flex: 0 0 386px; flex-direction: column; gap: 20px; width: 386px; scroll-snap-align: start; } .bestsellers__media { position: relative; width: 386px; height: 386px; overflow: hidden; border-radius: 10px; background: #fff; } .bestsellers__media-link { position: absolute; inset: 0; display: block; } .bestsellers__image { display: block; width: 100%; height: 100%; object-fit: cover; } .bestsellers__image--hover { position: absolute; inset: 0; opacity: 0; transition: opacity 0.35s ease; } .bestsellers__media:hover .bestsellers__image--hover, .bestsellers__media:focus-within .bestsellers__image--hover { opacity: 1; } @media (prefers-reduced-motion: reduce) { .bestsellers__image--hover { transition: none; } } .bestsellers__image--empty { background: #f3f3f3; } .bestsellers__badges { position: absolute; top: 10px; left: 10px; z-index: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; } .bestsellers__badge { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; border-radius: 2px; color: #000; font-size: 10px; font-weight: 300; line-height: normal; text-transform: uppercase; } .bestsellers__badge--best { background: #bfffb2; } .bestsellers__badge--skin { background: #f7c585; } .bestsellers__wish { position: absolute; top: 20px; right: 20px; z-index: 1; display: grid; width: 25px; height: 25px; place-items: center; padding: 0; border: 0; background: transparent; cursor: pointer; } .bestsellers__wish-icon { display: block; width: 25px; height: 25px; } .bestsellers__wish-icon svg { display: block; } .bestsellers__wish.is-active svg path { fill: #000; } .bestsellers__info { display: flex; flex-direction: column; gap: 15px; } .bestsellers__copy { display: flex; flex-direction: column; gap: 5px; } .bestsellers__title { display: block; overflow: hidden; color: #000; font-size: 18px; font-weight: 700; line-height: normal; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; } .bestsellers__subtitle, .bestsellers__reviews, .bestsellers__empty { margin: 0; } .bestsellers__subtitle { overflow: hidden; color: #808181; font-size: 14px; font-weight: 300; line-height: normal; text-overflow: ellipsis; white-space: nowrap; } .bestsellers__rating { display: flex; align-items: center; gap: 10px; } .bestsellers__stars { display: flex; align-items: center; gap: 1px; } .bestsellers__star { display: block; width: 10px; height: 10px; } .bestsellers__star svg { display: block; } .bestsellers__star.is-off { opacity: 0.25; } .bestsellers__reviews { color: #000; font-size: 9px; font-weight: 300; line-height: normal; white-space: nowrap; } .bestsellers__prices { display: flex; align-items: center; gap: 32px; } .bestsellers__price, .bestsellers__compare { font-size: 16px; line-height: normal; } .bestsellers__price { font-weight: 700; } .bestsellers__compare { color: #808181; font-weight: 400; text-decoration: line-through; } .bestsellers__actions { position: absolute; right: 20px; bottom: 10px; left: 20px; z-index: 2; display: flex; gap: 10px; margin: 0; opacity: 0; pointer-events: none; transition: opacity 0.25s ease; } .bestsellers__media:hover .bestsellers__actions, .bestsellers__media:focus-within .bestsellers__actions { opacity: 1; pointer-events: auto; } .bestsellers__bag, .bestsellers__buy { display: flex; align-items: center; justify-content: center; height: 50px; padding: 15px; border: 0; border-radius: 60px; box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1); cursor: pointer; } .bestsellers__bag { flex: 0 0 50px; width: 50px; background: #000; } .bestsellers__bag img { display: block; width: 25px; height: 25px; } .bestsellers__buy { flex: 1 1 auto; background: #9dd6c7; color: #000; font-family: Archivo, sans-serif; font-size: 16px; font-weight: 300; line-height: normal; } .bestsellers__bag:disabled, .bestsellers__buy:disabled { cursor: default; opacity: 0.55; } .bestsellers__empty { color: #000; font-size: 14px; font-weight: 400; } .bestsellers__more:focus-visible, .bestsellers__bag:focus-visible, .bestsellers__buy:focus-visible, .bestsellers__arrow:focus-visible, .bestsellers__wish:focus-visible, .bestsellers__title:focus-visible, .bestsellers__media-link:focus-visible, .bestsellers__promo:focus-visible { outline: 2px solid #000; outline-offset: 2px; } @media (max-width: 1439px) { .bestsellers__header { padding-inline: 40px; } .bestsellers__track { padding-right: 40px; } } @media (max-width: 1024px) { .bestsellers { padding-top: 40px; } .bestsellers__header { margin-bottom: 10px; padding-inline: 15px; } .bestsellers__heading { font-size: 20px; } .bestsellers__more { padding: 0; font-size: 14px; } .bestsellers__arrows { display: none; } .bestsellers__body { flex-direction: column; gap: 20px; } .bestsellers__promo { flex-basis: auto; width: calc(100% - 30px); height: 460px; margin-inline: 15px; border-radius: 10px; } .bestsellers__progress { margin-top: 24px; } .bestsellers__viewport { width: 100%; min-height: 370px; cursor: auto; } .bestsellers__track { gap: 20px; padding-right: 15px; padding-left: 15px; } .bestsellers__card { flex-basis: 245px; gap: 10px; width: 245px; } .bestsellers__media { width: 245px; height: 244px; } .bestsellers__badges { top: 5px; left: 5px; } .bestsellers__badge { font-size: 7px; } .bestsellers__wish { top: 10px; right: 11px; } .bestsellers__info { gap: 10px; } .bestsellers__title { font-size: 14px; } .bestsellers__subtitle { font-size: 10px; } .bestsellers__reviews { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); } .bestsellers__rating { position: relative; } .bestsellers__price, .bestsellers__compare { font-size: 14px; } .bestsellers__prices { gap: 16px; } .bestsellers__actions { right: 8px; bottom: 8px; left: 8px; gap: 6px; opacity: 1; pointer-events: auto; } .bestsellers__bag, .bestsellers__buy { height: 36px; padding: 0 8px; } .bestsellers__bag { flex-basis: 36px; width: 36px; } .bestsellers__bag img { width: 18px; height: 18px; } .bestsellers__buy { font-size: 12px; } } @media (prefers-reduced-motion: reduce) { .bestsellers__viewport { scroll-behavior: auto; } } {% endstylesheet %} {% javascript %} (() => { const wishlistKey = 'seasons-wishlist'; const readWishlist = () => { try { const stored = JSON.parse(window.localStorage.getItem(wishlistKey)); return Array.isArray(stored) ? stored.map(String) : []; } catch (error) { return []; } }; const writeWishlist = (ids) => { window.localStorage.setItem(wishlistKey, JSON.stringify(ids)); }; const applyWishlist = (root) => { const saved = readWishlist(); root.querySelectorAll('[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'); button.setAttribute('aria-label', active ? button.dataset.labelSaved : button.dataset.labelSave); }); }; const setCartCount = (count) => { const link = document.querySelector('.header__cart'); if (!link || count < 1) return; let badge = link.querySelector('[data-cart-count]'); if (!badge) { badge = document.createElement('span'); badge.className = 'absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-brand-mint px-[3px] text-[10px] font-medium leading-none text-black'; badge.setAttribute('data-cart-count', ''); link.appendChild(badge); } badge.textContent = String(count); link.setAttribute('aria-label', link.getAttribute('aria-label').replace(/\d+/, String(count))); }; const updateArrows = (root) => { const viewport = root.querySelector('[data-viewport]'); const prev = root.querySelector('[data-slider-prev]'); const next = root.querySelector('[data-slider-next]'); if (!viewport || !prev || !next) return; const max = viewport.scrollWidth - viewport.clientWidth; prev.disabled = viewport.scrollLeft <= 2; next.disabled = viewport.scrollLeft >= max - 2; updateProgress(root); }; const updateProgress = (root) => { const viewport = root.querySelector('[data-viewport]'); const bar = root.querySelector('[data-progress-bar]'); if (!viewport || !bar) return; const max = viewport.scrollWidth - viewport.clientWidth; const visible = viewport.scrollWidth > 0 ? viewport.clientWidth / viewport.scrollWidth : 1; const width = Math.min(Math.max(visible * 100, 12), 100); const travel = 100 - width; const progress = max <= 2 ? 0 : viewport.scrollLeft / max; bar.style.width = `${width}%`; bar.style.left = `${progress * travel}%`; }; const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)'); const pauseAutoplay = (root) => { if (!root._bestsellersTimer) return; window.clearInterval(root._bestsellersTimer); root._bestsellersTimer = null; }; const startAutoplay = (root) => { pauseAutoplay(root); if (reduceMotion.matches || root.dataset.paused === 'true') return; root._bestsellersTimer = window.setInterval(() => { const viewport = root.querySelector('[data-viewport]'); if (!viewport) return; const max = viewport.scrollWidth - viewport.clientWidth; if (max <= 2) return; if (viewport.scrollLeft >= max - 2) { viewport.scrollTo({ left: 0, behavior: 'smooth' }); return; } scrollByCard(root, 1); }, 4000); }; const scrollByCard = (root, direction) => { const viewport = root.querySelector('[data-viewport]'); const card = root.querySelector('.bestsellers__card'); if (!viewport || !card) return; const track = root.querySelector('[data-track]'); const gap = track ? parseFloat(window.getComputedStyle(track).columnGap) || 0 : 0; const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches; viewport.scrollBy({ left: direction * (card.getBoundingClientRect().width + gap), behavior: reduce ? 'auto' : 'smooth', }); }; const loadBestSellers = async (root) => { if (root.dataset.sorted === 'true' || !root.dataset.feed) return; if (window.Shopify && window.Shopify.designMode) return; try { const response = await fetch(root.dataset.feed, { headers: { Accept: 'text/html' } }); if (!response.ok) { root.dataset.sorted = 'true'; return; } const html = await response.text(); const parsed = new DOMParser().parseFromString(html, 'text/html'); const limit = Number(root.dataset.limit) || 8; const cards = Array.from(parsed.querySelectorAll('.bestsellers__card')).slice(0, limit); const track = root.querySelector('[data-track]'); if (!track || !cards.length) { root.dataset.sorted = 'true'; return; } track.replaceChildren(...cards.map((card) => document.importNode(card, true))); applyWishlist(root); updateArrows(root); root.dataset.sorted = 'true'; startAutoplay(root); } catch (error) { root.dataset.sorted = 'true'; } }; const boot = (root) => { if (!root || root.dataset.ready === 'true') return; root.dataset.ready = 'true'; const viewport = root.querySelector('[data-viewport]'); if (!viewport) return; applyWishlist(root); updateArrows(root); viewport.addEventListener('scroll', () => updateArrows(root), { passive: true }); window.addEventListener('resize', () => updateArrows(root)); root.addEventListener('mouseenter', () => { root.dataset.paused = 'true'; pauseAutoplay(root); }); root.addEventListener('mouseleave', () => { delete root.dataset.paused; if (!viewport.classList.contains('is-dragging')) startAutoplay(root); }); let pointerId = null; let startX = 0; let startScroll = 0; let moved = false; viewport.addEventListener('pointerdown', (event) => { if (event.pointerType !== 'mouse' || event.button !== 0) return; if (event.target.closest('a, button')) return; pointerId = event.pointerId; startX = event.clientX; startScroll = viewport.scrollLeft; moved = false; pauseAutoplay(root); viewport.classList.add('is-dragging'); viewport.setPointerCapture(pointerId); }); viewport.addEventListener('pointermove', (event) => { if (event.pointerId !== pointerId) return; const delta = event.clientX - startX; if (Math.abs(delta) > 4) moved = true; viewport.scrollLeft = startScroll - delta; }); const endDrag = (event) => { if (event.pointerId !== pointerId) return; pointerId = null; viewport.classList.remove('is-dragging'); updateArrows(root); if (root.dataset.paused !== 'true') startAutoplay(root); if (!moved) return; viewport.addEventListener('click', (clickEvent) => { clickEvent.preventDefault(); clickEvent.stopPropagation(); }, { capture: true, once: true }); }; viewport.addEventListener('pointerup', endDrag); viewport.addEventListener('pointercancel', endDrag); startAutoplay(root); loadBestSellers(root); }; document.querySelectorAll('[data-bestsellers]').forEach(boot); document.addEventListener('shopify:section:load', (event) => { const root = event.target.querySelector('[data-bestsellers]'); if (root) boot(root); }); if (!window.__seasonBestsellers) { window.__seasonBestsellers = true; document.addEventListener('click', (event) => { const arrow = event.target.closest('[data-slider-prev], [data-slider-next]'); if (arrow) { const root = arrow.closest('[data-bestsellers]'); if (!root || arrow.disabled) return; scrollByCard(root, arrow.hasAttribute('data-slider-next') ? 1 : -1); if (root.dataset.paused !== 'true') startAutoplay(root); return; } const wish = event.target.closest('[data-wishlist]'); if (!wish) return; const root = wish.closest('[data-bestsellers]'); if (!root) return; const id = String(wish.dataset.productId); const saved = readWishlist(); const next = saved.includes(id) ? saved.filter((item) => item !== id) : saved.concat(id); writeWishlist(next); applyWishlist(root); }); document.addEventListener('submit', async (event) => { const form = event.target; if (!(form instanceof HTMLFormElement) || !form.classList.contains('bestsellers__form')) return; const root = form.closest('[data-bestsellers]'); if (!root) 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(root.dataset.cartAddUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ id: variantId, quantity: 1 }), }); if (!addResponse.ok) { form.submit(); return; } if (buyNow && root.dataset.checkoutUrl) { window.location.href = root.dataset.checkoutUrl; return; } const cartResponse = await fetch(root.dataset.cartUrl, { headers: { Accept: 'application/json' } }); const cart = await cartResponse.json(); if (typeof cart.item_count === 'number') setCartCount(cart.item_count); document.dispatchEvent(new CustomEvent('season:cart:open')); } catch (error) { form.submit(); } finally { if (!buyNow) { buttons.forEach((item) => { item.disabled = false; }); } } }); } })(); {% endjavascript %} {% schema %} { "name": "t:bestsellers.name", "tag": "section", "class": "bestsellers-section", "disabled_on": { "groups": ["header", "footer"] }, "settings": [ { "type": "text", "id": "heading", "label": "t:bestsellers.heading", "default": "Más vendidos" }, { "type": "collection", "id": "collection", "label": "t:bestsellers.collection", "info": "t:bestsellers.collection_info" }, { "type": "range", "id": "products_to_show", "label": "t:bestsellers.products_to_show", "min": 4, "max": 12, "step": 1, "default": 8 }, { "type": "header", "content": "t:bestsellers.promo" }, { "type": "image_picker", "id": "promo_image", "label": "t:bestsellers.promo_image", "info": "t:bestsellers.promo_image_info" }, { "type": "url", "id": "promo_link", "label": "t:bestsellers.promo_link" } ], "presets": [ { "name": "t:bestsellers.name" } ] } {% endschema %}