{% 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 = 'new_products.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: 'created-descending' assign feed_url = more_url | append: '&view=new-products-data' if product_collection.default_sort_by == 'created-descending' assign already_sorted = true endif endif assign video_src = blank if section.settings.video != blank for source in section.settings.video.sources if source.mime_type == 'video/mp4' or source.format == 'mp4' assign video_src = source.url endif endfor endif if video_src == blank and section.settings.promo_link == blank assign video_src = 'nuevos-productos.mp4' | asset_url endif assign poster = section.settings.poster assign poster_url = blank if poster != blank assign poster_url = poster | image_url: width: 1000 endif if video_src == blank and 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 assign show_promo = false if poster != blank or video_src != blank assign show_promo = true endif %}

{{ heading | escape }}

{% if show_promo %} <{{ promo_tag }} class="bestsellers__promo" {% if promo_tag == 'a' %} href="{{ section.settings.promo_link }}" {% endif %} > {% if poster != blank %} {{ poster | 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 new-products__poster', loading: 'lazy' }} {% endif %} {% if video_src != blank %} {% endif %} {% 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 %}
{% javascript %} (() => { const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; const markPlaying = (video) => { const root = video.closest('[data-new-products]'); if (!root) return; root.classList.toggle('is-playing', !video.paused && !video.ended); }; const ensureSource = (video) => { if (video.dataset.loaded === 'true' || !video.dataset.src || reduceMotion) return; video.dataset.loaded = 'true'; video.src = video.dataset.src; video.load(); }; const playVideo = (video) => { ensureSource(video); if (video.dataset.loaded !== 'true') return; const attempt = video.play(); if (attempt && typeof attempt.catch === 'function') attempt.catch(() => {}); }; const watch = (video) => { video.addEventListener('playing', () => markPlaying(video)); video.addEventListener('pause', () => markPlaying(video)); video.addEventListener('ended', () => markPlaying(video)); if (!('IntersectionObserver' in window)) { playVideo(video); return; } const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { playVideo(entry.target); return; } if (entry.target.dataset.loaded === 'true') entry.target.pause(); }); }, { rootMargin: '200px 0px' }); observer.observe(video); }; const boot = (root) => { if (!root || root.dataset.videoReady === 'true') return; root.dataset.videoReady = 'true'; const video = root.querySelector('[data-new-products-video]'); if (video) watch(video); }; document.querySelectorAll('[data-new-products]').forEach(boot); document.addEventListener('shopify:section:load', (event) => { const root = event.target.querySelector('[data-new-products]'); if (root) boot(root); }); })(); {% endjavascript %} {% schema %} { "name": "t:new_products.name", "tag": "section", "class": "new-products-section", "disabled_on": { "groups": ["header", "footer"] }, "settings": [ { "type": "text", "id": "heading", "label": "t:new_products.heading", "default": "Nuevos productos" }, { "type": "collection", "id": "collection", "label": "t:new_products.collection", "info": "t:new_products.collection_info" }, { "type": "range", "id": "products_to_show", "label": "t:new_products.products_to_show", "min": 4, "max": 12, "step": 1, "default": 8 }, { "type": "header", "content": "t:new_products.media" }, { "type": "image_picker", "id": "poster", "label": "t:new_products.poster", "info": "t:new_products.poster_info" }, { "type": "video", "id": "video", "label": "t:new_products.video", "info": "t:new_products.video_info" }, { "type": "url", "id": "promo_link", "label": "t:new_products.promo_link", "info": "t:new_products.promo_link_info" } ], "presets": [ { "name": "t:new_products.name" } ] } {% endschema %}