Ajustes antes de produccion
This commit is contained in:
+553
-35
@@ -30,8 +30,37 @@
|
||||
if excerpt == blank
|
||||
assign excerpt = product.metafields.custom.short_description.value | default: product.metafields.custom.excerpt.value
|
||||
endif
|
||||
if excerpt == blank
|
||||
assign excerpt = product.description | strip_html | truncate: 180
|
||||
assign excerpt_from_description = false
|
||||
if excerpt == blank and product.description != blank
|
||||
assign excerpt_from_description = true
|
||||
assign excerpt_parts = product.description | replace: '</p>', '[[br]]' | replace: '</h1>', '[[br]]' | replace: '</h2>', '[[br]]' | replace: '</h3>', '[[br]]' | replace: '</h4>', '[[br]]' | replace: '</h5>', '[[br]]' | replace: '</h6>', '[[br]]' | replace: '</li>', '[[br]]' | replace: '<br>', '[[br]]' | replace: '<br/>', '[[br]]' | replace: '<br />', '[[br]]' | strip_html | split: '[[br]]'
|
||||
comment
|
||||
First paragraph: the first <p> of the description (falls back to the first text block).
|
||||
endcomment
|
||||
assign excerpt = ''
|
||||
if product.description contains '</p>'
|
||||
assign excerpt = product.description | split: '</p>' | first | split: '<p' | last | 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
|
||||
@@ -132,6 +161,17 @@
|
||||
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
|
||||
%}
|
||||
@@ -146,8 +186,14 @@
|
||||
>
|
||||
<div class="product__hero">
|
||||
<div class="product__gallery">
|
||||
<div class="product__main">
|
||||
{% if main_image %}
|
||||
{% if main_image %}
|
||||
<button
|
||||
type="button"
|
||||
class="product__main"
|
||||
data-gallery-open
|
||||
data-full="{{ main_image | image_url: width: 2000 }}"
|
||||
aria-label="{{ 'product_page.gallery_open' | t }}"
|
||||
>
|
||||
{{
|
||||
main_image
|
||||
| image_url: width: 1400
|
||||
@@ -156,14 +202,16 @@
|
||||
alt: main_alt,
|
||||
loading: 'eager',
|
||||
fetchpriority: 'high',
|
||||
widths: '700, 1000, 1400',
|
||||
widths: '360, 540, 720, 1000, 1400',
|
||||
sizes: '(min-width: 1120px) 58vw, 100vw',
|
||||
data-main-image: 'true'
|
||||
}}
|
||||
{% else %}
|
||||
</button>
|
||||
{% else %}
|
||||
<div class="product__main">
|
||||
{{ 'product-1' | placeholder_svg_tag: 'product__main-image' }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if product.images.size > 1 %}
|
||||
{% assign gallery_count = 0 %}
|
||||
{% if main_image != blank %}
|
||||
@@ -176,7 +224,13 @@
|
||||
{% endfor %}
|
||||
<div class="product__thumbs" data-product-thumbs>
|
||||
{% if main_image != blank %}
|
||||
<div class="product__thumb product__thumb--main">
|
||||
<button
|
||||
type="button"
|
||||
class="product__thumb product__thumb--main"
|
||||
data-gallery-open
|
||||
data-full="{{ main_image | image_url: width: 2000 }}"
|
||||
aria-label="{{ 'product_page.gallery_open' | t }}"
|
||||
>
|
||||
{{
|
||||
main_image
|
||||
| image_url: width: 1400
|
||||
@@ -184,27 +238,33 @@
|
||||
alt: main_alt,
|
||||
loading: 'eager',
|
||||
fetchpriority: 'high',
|
||||
widths: '700, 1000, 1400',
|
||||
sizes: '100vw',
|
||||
widths: '360, 540, 720, 1000, 1400',
|
||||
sizes: '92vw',
|
||||
draggable: false
|
||||
}}
|
||||
</div>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% for image in product.images %}
|
||||
{% if image.id != main_image.id %}
|
||||
{% assign thumb_alt = image.alt | default: product.title %}
|
||||
<div class="product__thumb">
|
||||
<button
|
||||
type="button"
|
||||
class="product__thumb"
|
||||
data-gallery-open
|
||||
data-full="{{ image | image_url: width: 2000 }}"
|
||||
aria-label="{{ 'product_page.gallery_open' | t }}"
|
||||
>
|
||||
{{
|
||||
image
|
||||
| image_url: width: 900
|
||||
| image_tag:
|
||||
alt: thumb_alt,
|
||||
loading: 'lazy',
|
||||
widths: '400, 700, 900',
|
||||
sizes: '(max-width: 767px) 100vw, (min-width: 1120px) 28vw, 50vw',
|
||||
widths: '360, 540, 720, 900',
|
||||
sizes: '(max-width: 767px) 92vw, (min-width: 1120px) 28vw, 50vw',
|
||||
draggable: false
|
||||
}}
|
||||
</div>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
@@ -223,6 +283,15 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if main_image %}
|
||||
<dialog class="product-lightbox" data-gallery-lightbox>
|
||||
<button type="button" class="product-lightbox__nav product-lightbox__nav--prev" data-gallery-prev aria-label="{{ 'product_page.gallery_prev' | t }}" hidden>‹</button>
|
||||
<img class="product-lightbox__image" alt="" data-gallery-image>
|
||||
<button type="button" class="product-lightbox__nav product-lightbox__nav--next" data-gallery-next aria-label="{{ 'product_page.gallery_next' | t }}" hidden>›</button>
|
||||
<button type="button" class="product-lightbox__close" data-gallery-close aria-label="{{ 'product_page.gallery_close' | t }}">×</button>
|
||||
<p class="product-lightbox__count" data-gallery-count data-template="{{ 'product_page.gallery_count' | t: current: '__C__', total: '__T__' }}" hidden></p>
|
||||
</dialog>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="product__details">
|
||||
@@ -242,7 +311,7 @@
|
||||
<p class="product__subtitle">{{ subtitle | escape }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if rating_count > 0 %}
|
||||
{% if rating_count > 0 and low_rating == false %}
|
||||
<div class="product__rating">
|
||||
<span class="product__stars" aria-hidden="true">
|
||||
{% for star in (1..5) %}
|
||||
@@ -263,7 +332,37 @@
|
||||
</p>
|
||||
|
||||
{% if excerpt != blank %}
|
||||
<p class="product__excerpt">{{ excerpt | escape }}</p>
|
||||
{% if excerpt_from_description %}
|
||||
<div class="product__excerpt" data-excerpt>
|
||||
<p class="product__excerpt-short">{{ excerpt | escape }}</p>
|
||||
{%- if excerpt_has_more -%}
|
||||
<div class="product__excerpt-full" id="ProductExcerptFull-{{ section.id }}" hidden>
|
||||
{%- for part in excerpt_parts -%}
|
||||
{%- assign part_text = part | strip -%}
|
||||
{%- if part_text != blank -%}<p>{{ part_text | escape }}</p>{%- endif -%}
|
||||
{%- endfor -%}
|
||||
</div>
|
||||
<button type="button" class="product__excerpt-toggle" aria-expanded="false" aria-controls="ProductExcerptFull-{{ section.id }}" data-more="Leer más" data-less="Leer menos">Leer más</button>
|
||||
<script nolazy>
|
||||
(function () {
|
||||
var root = document.currentScript.closest('[data-excerpt]');
|
||||
var btn = root.querySelector('.product__excerpt-toggle');
|
||||
var full = root.querySelector('.product__excerpt-full');
|
||||
var shortEl = root.querySelector('.product__excerpt-short');
|
||||
if (btn.dataset.bound) return; btn.dataset.bound = '1';
|
||||
btn.addEventListener('click', function () {
|
||||
var open = btn.getAttribute('aria-expanded') !== 'true';
|
||||
full.hidden = !open; shortEl.hidden = open;
|
||||
btn.setAttribute('aria-expanded', String(open));
|
||||
btn.textContent = open ? btn.dataset.less : btn.dataset.more;
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{%- endif -%}
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="product__excerpt">{{ excerpt | escape }}</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% form 'product', product, id: 'product-form', class: 'product__form' %}
|
||||
@@ -315,18 +414,35 @@
|
||||
</div>
|
||||
{% endunless %}
|
||||
|
||||
<ul class="product__trust">
|
||||
<ul class="product__trust overflow-hidden">
|
||||
<li class="product__trust-row">
|
||||
<span class="product__trust-icon">{{ 'icon-marquee-shipping.svg' | inline_asset_content }}</span>
|
||||
<span>{{ 'product_page.shipping' | t }}</span>
|
||||
</li>
|
||||
<li class="product__trust-row">
|
||||
<span class="product__trust-icon">{{ 'icon-marquee-card.svg' | inline_asset_content }}</span>
|
||||
<span>{{ 'product_page.payment' | t }}</span>
|
||||
<span class="inline-flex min-w-0 items-center gap-x-2 gap-y-1">
|
||||
<span>{{ 'product_page.payment' | t }}</span>
|
||||
<span class="inline-flex flex-nowrap items-center gap-1">
|
||||
<img class="h-6 w-auto max-w-none shrink-0" src="{{ 'pay-visa.svg' | asset_url }}" alt="Visa" width="38" height="24" loading="lazy" decoding="async">
|
||||
<img class="h-6 w-auto max-w-none shrink-0" src="{{ 'pay-mastercard.svg' | asset_url }}" alt="Mastercard" width="38" height="24" loading="lazy" decoding="async">
|
||||
<img class="h-6 w-auto max-w-none shrink-0" src="{{ 'pay-amex.svg' | asset_url }}" alt="American Express" width="38" height="24" loading="lazy" decoding="async">
|
||||
<img class="h-6 w-auto max-w-none shrink-0" src="{{ 'pay-paypal.svg' | asset_url }}" alt="PayPal" width="38" height="24" loading="lazy" decoding="async">
|
||||
{{ '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' }}
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
<li class="product__trust-row">
|
||||
<span class="product__trust-icon">{{ 'icon-marquee-wallet.svg' | inline_asset_content }}</span>
|
||||
<span>{{ 'product_page.installments' | t }}</span>
|
||||
<span class="inline-flex min-w-0 items-center gap-x-2 gap-y-1">
|
||||
<span>{{ 'product_page.installments_with' | t }}</span>
|
||||
<span class="inline-flex flex-nowrap items-center gap-1">
|
||||
<img class="h-6 w-auto max-w-none shrink-0" src="{{ 'pay-mercadopago.svg' | asset_url }}" alt="Mercado Pago" width="38" height="24" loading="lazy" decoding="async">
|
||||
<img class="h-6 w-auto max-w-none shrink-0" src="{{ 'pay-kueski.svg' | asset_url }}" alt="Kueski Pay" width="48" height="30" loading="lazy" decoding="async">
|
||||
<img class="h-6 w-auto max-w-none shrink-0" src="{{ 'pay-aplazo.svg' | asset_url }}" alt="Aplazo" width="48" height="30" loading="lazy" decoding="async">
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
<li class="product__trust-row">
|
||||
<span class="product__trust-icon">{{ 'icon-marquee-guarantee.svg' | inline_asset_content }}</span>
|
||||
@@ -334,6 +450,7 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="product__subscription" data-kv-subscription-target></div>
|
||||
<div class="product__purchase">
|
||||
<div class="product__qty">
|
||||
<button type="button" data-qty="down" aria-label="{{ 'product_page.decrease' | t }}">−</button>
|
||||
@@ -360,6 +477,113 @@
|
||||
</button>
|
||||
{% endform %}
|
||||
|
||||
{% if additional_checkout_buttons %}
|
||||
<div class="product__express" data-wallets {% unless current_variant.available %}hidden{% endunless %}>
|
||||
<p class="product__express-label">{{ 'product_page.express' | t }}</p>
|
||||
{{ content_for_additional_checkout_buttons }}
|
||||
</div>
|
||||
<script nolazy>
|
||||
(() => {
|
||||
const root = document.querySelector('[data-product-page]');
|
||||
const wallets = root?.querySelector('[data-wallets]');
|
||||
const form = root?.querySelector('.product__form');
|
||||
if (!wallets || !form || wallets.dataset.bound) return;
|
||||
wallets.dataset.bound = 'true';
|
||||
|
||||
const rootPath = window.Shopify?.routes?.root || '/';
|
||||
let checkoutStarted = false;
|
||||
|
||||
const request = (url, body) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', url, false);
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
if (body) xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(body || null);
|
||||
return xhr.status >= 200 && xhr.status < 300 ? xhr.responseText : '';
|
||||
};
|
||||
|
||||
const variantId = () => Number(form.querySelector('[name="id"]')?.value);
|
||||
const variantQuantity = () => Math.max(1, Number(form.querySelector('[name="quantity"]')?.value) || 1);
|
||||
|
||||
const addCurrentVariant = () => {
|
||||
checkoutStarted = true;
|
||||
const id = variantId();
|
||||
const quantity = variantQuantity();
|
||||
if (!id) return;
|
||||
try {
|
||||
const cartRequest = new XMLHttpRequest();
|
||||
cartRequest.open('GET', `${rootPath}cart.js`, false);
|
||||
cartRequest.setRequestHeader('Accept', 'application/json');
|
||||
cartRequest.send();
|
||||
const cart = cartRequest.status === 200 ? JSON.parse(cartRequest.responseText) : { items: [] };
|
||||
const already = (cart.items || []).some((item) => item.variant_id === id);
|
||||
if (already) return;
|
||||
request(`${form.action}.js`, JSON.stringify({ id, quantity }));
|
||||
} catch (error) {}
|
||||
};
|
||||
|
||||
const walletNames = (element) => {
|
||||
try {
|
||||
return JSON.parse(element?.getAttribute('wallet-configs') || '[]').map((wallet) => wallet.name);
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const ensureGooglePay = async () => {
|
||||
const current = wallets.querySelector('shopify-accelerated-checkout-cart');
|
||||
if (!current || wallets.hidden || walletNames(current).includes('google_pay')) return;
|
||||
const id = variantId();
|
||||
if (!id) return;
|
||||
|
||||
let lineKey = '';
|
||||
try {
|
||||
const addedResponse = await fetch(`${form.action}.js`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify({ id, quantity: variantQuantity() }),
|
||||
});
|
||||
if (!addedResponse.ok) return;
|
||||
const added = await addedResponse.json();
|
||||
lineKey = added.key || added.items?.find((item) => item.variant_id === id)?.key || '';
|
||||
const sectionId = root.closest('[id^="shopify-section"]')?.id?.replace('shopify-section-', '');
|
||||
const html = await fetch(`${window.location.pathname}?section_id=${encodeURIComponent(sectionId || '')}`, {
|
||||
cache: 'no-store',
|
||||
headers: { Accept: 'text/html' },
|
||||
}).then((response) => response.text());
|
||||
const next = new DOMParser().parseFromString(html, 'text/html').querySelector('shopify-accelerated-checkout-cart');
|
||||
if (!next || !walletNames(next).includes('google_pay')) return;
|
||||
current.replaceWith(next);
|
||||
await new Promise((resolve) => {
|
||||
const started = Date.now();
|
||||
const waitForButton = () => {
|
||||
if (wallets.querySelector('shopify-google-pay-button') || Date.now() - started > 8000) resolve();
|
||||
else window.setTimeout(waitForButton, 200);
|
||||
};
|
||||
waitForButton();
|
||||
});
|
||||
} catch (error) {
|
||||
} finally {
|
||||
if (lineKey && !checkoutStarted) {
|
||||
await fetch(`${rootPath}cart/change.js`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify({ id: lineKey, quantity: 0 }),
|
||||
}).catch(() => {});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
wallets.addEventListener('pointerdown', addCurrentVariant);
|
||||
window.addEventListener('blur', () => {
|
||||
const active = document.activeElement;
|
||||
if (active && wallets.contains(active)) addCurrentVariant();
|
||||
});
|
||||
ensureGooglePay();
|
||||
})();
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
{% liquid
|
||||
assign sticky_image = current_variant.image
|
||||
if sticky_image == blank and current_variant.featured_media
|
||||
@@ -413,6 +637,51 @@
|
||||
document.body.appendChild(bar);
|
||||
})();
|
||||
</script>
|
||||
<script nolazy>
|
||||
// Subscription apps (Konvertti Addons) inject their purchase-options widget next to the
|
||||
// add-to-cart button. Keep the layout: widget on its own row above [qty | Añadir], "Comprar" below,
|
||||
// and mirror the chosen option's price in the sticky footer bar.
|
||||
(function () {
|
||||
if (window.__seasonPurchaseOptions) return;
|
||||
window.__seasonPurchaseOptions = true;
|
||||
var WIDGETS = '.kv-sub, [data-kv-subscription]';
|
||||
var tidy = function () {
|
||||
var row = document.querySelector('#product-form .product__purchase');
|
||||
if (!row) return;
|
||||
row.querySelectorAll(WIDGETS).forEach(function (w) {
|
||||
var node = w.closest('.shopify-block') && row.contains(w.closest('.shopify-block')) ? w.closest('.shopify-block') : w;
|
||||
if (node.parentElement === row) row.parentElement.insertBefore(node, row);
|
||||
});
|
||||
};
|
||||
var priceText = function (el) {
|
||||
if (!el) return '';
|
||||
var m = (el.textContent || '').match(/[$€£]\s?[\d.,]+|[\d.,]+\s?[$€£]/);
|
||||
return m ? m[0].trim() : '';
|
||||
};
|
||||
var syncSticky = function () {
|
||||
var sticky = document.querySelector('[data-sticky-price]');
|
||||
var checked = document.querySelector('.kv-sub input[type="radio"]:checked');
|
||||
if (!sticky || !checked) return;
|
||||
var label = checked.closest('.kv-sub__option');
|
||||
var price = priceText(label && label.querySelector('.kv-sub__price'));
|
||||
if (price) sticky.textContent = price;
|
||||
};
|
||||
var run = function () { tidy(); syncSticky(); };
|
||||
document.addEventListener('change', function (e) { if (e.target.closest && e.target.closest('.kv-sub')) window.setTimeout(run, 0); });
|
||||
document.addEventListener('kv:plan-change', function () { window.setTimeout(run, 0); });
|
||||
document.addEventListener('click', function (e) { if (e.target.closest && e.target.closest('.kv-sub, [data-variant-option], .product__variant')) window.setTimeout(run, 50); });
|
||||
var start = function () {
|
||||
run();
|
||||
var form = document.getElementById('product-form');
|
||||
if (form && 'MutationObserver' in window) {
|
||||
var t = 0;
|
||||
new MutationObserver(function () { window.clearTimeout(t); t = window.setTimeout(run, 30); })
|
||||
.observe(form.parentElement || form, { childList: true, subtree: true, characterData: true });
|
||||
}
|
||||
};
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start); else start();
|
||||
})();
|
||||
</script>
|
||||
|
||||
<button
|
||||
class="product__favorite"
|
||||
@@ -421,9 +690,6 @@
|
||||
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 }}"
|
||||
>
|
||||
<svg width="22" height="22" viewBox="0 0 25 25" aria-hidden="true" focusable="false">
|
||||
<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" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
@@ -547,7 +813,7 @@
|
||||
{% 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 %}
|
||||
{% render 'collection-card', product: item, form_suffix: also_key, badge_mode: 'collection' %}
|
||||
{% assign also_shown = also_shown | plus: 1 %}
|
||||
{% endunless %}
|
||||
{% endif %}
|
||||
@@ -575,6 +841,8 @@
|
||||
data-product-handle="{{ product.handle | escape }}"
|
||||
data-shop="{{ shop.permanent_domain | escape }}"
|
||||
data-reviews-shop="{{ section.settings.reviews_shop | escape }}"
|
||||
data-min-rating="{{ reviews_min_rating }}"
|
||||
data-product-image="{% if product.featured_image %}https:{{ product.featured_image | image_url: width: 96 }}{% endif %}"
|
||||
data-reviews-storefront="{{ section.settings.reviews_storefront | escape }}"
|
||||
>
|
||||
<div class="product__reviews-head">
|
||||
@@ -687,7 +955,7 @@
|
||||
|
||||
const applyWish = () => {
|
||||
const saved = readWishlist().map((item) => item.id);
|
||||
root.querySelectorAll('[data-product-wish]').forEach((button) => {
|
||||
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');
|
||||
@@ -709,29 +977,85 @@
|
||||
});
|
||||
|
||||
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;
|
||||
if (event.pointerType === 'mouse' && event.button !== 0) return;
|
||||
pointerId = event.pointerId;
|
||||
startX = event.clientX;
|
||||
startScroll = thumbs.scrollLeft;
|
||||
thumbs.classList.add('is-dragging');
|
||||
thumbs.setPointerCapture(pointerId);
|
||||
dragged = false;
|
||||
pending = event.target.closest('[data-gallery-open]');
|
||||
});
|
||||
|
||||
thumbs.addEventListener('pointermove', (event) => {
|
||||
if (event.pointerId !== pointerId) return;
|
||||
thumbs.scrollLeft = startScroll - (event.clientX - startX);
|
||||
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);
|
||||
@@ -750,12 +1074,88 @@
|
||||
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 || '');
|
||||
@@ -783,7 +1183,10 @@
|
||||
node.classList.toggle('is-selected', node === option);
|
||||
});
|
||||
const idInput = form?.querySelector('[name="id"]');
|
||||
if (idInput) idInput.value = option.dataset.id || idInput.value;
|
||||
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]');
|
||||
@@ -816,10 +1219,16 @@
|
||||
}
|
||||
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) {
|
||||
@@ -828,6 +1237,48 @@
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
@@ -906,6 +1357,7 @@
|
||||
list.replaceChildren(...nodes);
|
||||
block.hidden = false;
|
||||
block.dataset.filled = 'true';
|
||||
applyWish();
|
||||
} catch (error) {
|
||||
block.hidden = true;
|
||||
}
|
||||
@@ -936,7 +1388,15 @@
|
||||
return (parsed.body.textContent || '').trim();
|
||||
};
|
||||
|
||||
const renderReviews = (reviews, append) => {
|
||||
const avatarIcon = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="8" r="3.25" stroke="currentColor" stroke-width="1.4"/><path d="M5.2 19.4c1.15-3.15 3.35-4.7 6.8-4.7s5.65 1.55 6.8 4.7" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg>';
|
||||
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)));
|
||||
@@ -966,7 +1426,21 @@
|
||||
const avatar = document.createElement('span');
|
||||
avatar.className = 'product__avatar';
|
||||
avatar.setAttribute('aria-hidden', 'true');
|
||||
avatar.innerHTML = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="8" r="3.25" stroke="currentColor" stroke-width="1.4"/><path d="M5.2 19.4c1.15-3.15 3.35-4.7 6.8-4.7s5.65 1.55 6.8 4.7" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg>';
|
||||
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';
|
||||
@@ -978,6 +1452,33 @@
|
||||
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);
|
||||
});
|
||||
};
|
||||
@@ -1006,7 +1507,11 @@
|
||||
cache.set(page, await response.json());
|
||||
}
|
||||
const data = cache.get(page);
|
||||
renderReviews(data.reviews || [], append);
|
||||
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;
|
||||
@@ -1087,6 +1592,16 @@
|
||||
"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",
|
||||
@@ -1103,7 +1618,10 @@
|
||||
}
|
||||
],
|
||||
"disabled_on": {
|
||||
"groups": ["header", "footer"]
|
||||
"groups": [
|
||||
"header",
|
||||
"footer"
|
||||
]
|
||||
}
|
||||
}
|
||||
{% endschema %}
|
||||
|
||||
Reference in New Issue
Block a user