Compare commits
No commits in common. "main" and "correctif" have entirely different histories.
10 changed files with 65 additions and 234 deletions
|
|
@ -1054,10 +1054,6 @@ body.is-fullscreen {
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-content {
|
|
||||||
display: contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
.store__nav {
|
.store__nav {
|
||||||
padding-top: calc(var(--spacing) * 1);
|
padding-top: calc(var(--spacing) * 1);
|
||||||
padding-bottom: calc(var(--spacing) * 0.5);
|
padding-bottom: calc(var(--spacing) * 0.5);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -5,10 +5,6 @@
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-content {
|
|
||||||
display: contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
.store__nav {
|
.store__nav {
|
||||||
padding-top: calc(var(--spacing) * 1);
|
padding-top: calc(var(--spacing) * 1);
|
||||||
padding-bottom: calc(var(--spacing) * 0.5);
|
padding-bottom: calc(var(--spacing) * 0.5);
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,6 @@
|
||||||
|
|
||||||
// Initialize event listeners
|
// Initialize event listeners
|
||||||
setupEventListeners();
|
setupEventListeners();
|
||||||
|
|
||||||
// Load initial cart state
|
|
||||||
loadCart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupEventListeners() {
|
function setupEventListeners() {
|
||||||
|
|
@ -63,18 +60,6 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCart() {
|
|
||||||
if (!cartInstance) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const cart = await cartInstance.getCart();
|
|
||||||
currentCart = cart;
|
|
||||||
renderCart();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading cart:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function openDrawer() {
|
function openDrawer() {
|
||||||
drawer.classList.add('is-open');
|
drawer.classList.add('is-open');
|
||||||
document.body.style.overflow = 'hidden';
|
document.body.style.overflow = 'hidden';
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
const handle = container.dataset.shopifyHandle;
|
const handle = container.dataset.shopifyHandle;
|
||||||
const language = container.dataset.language || "fr";
|
const language = container.dataset.language || 'fr';
|
||||||
const isEnglish = language === "en";
|
const isEnglish = language === 'en';
|
||||||
const loadingState = container.querySelector(".product-loading");
|
const loadingState = container.querySelector(".product-loading");
|
||||||
const contentState = container.querySelector(".product-content");
|
const contentState = container.querySelector(".product-content");
|
||||||
const errorState = container.querySelector(".product-error");
|
const errorState = container.querySelector(".product-error");
|
||||||
|
|
@ -63,8 +63,7 @@
|
||||||
function renderTitle(product, isEnglish) {
|
function renderTitle(product, isEnglish) {
|
||||||
const titleEl = document.querySelector("[data-product-title]");
|
const titleEl = document.querySelector("[data-product-title]");
|
||||||
if (titleEl) {
|
if (titleEl) {
|
||||||
const title =
|
const title = isEnglish && product.titleEn?.value
|
||||||
isEnglish && product.titleEn?.value
|
|
||||||
? product.titleEn.value
|
? product.titleEn.value
|
||||||
: product.title;
|
: product.title;
|
||||||
titleEl.textContent = title;
|
titleEl.textContent = title;
|
||||||
|
|
@ -82,9 +81,8 @@
|
||||||
function renderDetails(product, isEnglish) {
|
function renderDetails(product, isEnglish) {
|
||||||
const detailsEl = document.querySelector("[data-product-details]");
|
const detailsEl = document.querySelector("[data-product-details]");
|
||||||
if (detailsEl) {
|
if (detailsEl) {
|
||||||
const description =
|
const description = isEnglish && product.descriptionEn?.value
|
||||||
isEnglish && product.descriptionEn?.value
|
? product.descriptionEn.value
|
||||||
? product.descriptionEn.value.replaceAll("\n", "<br>")
|
|
||||||
: product.descriptionHtml || "";
|
: product.descriptionHtml || "";
|
||||||
detailsEl.innerHTML = description;
|
detailsEl.innerHTML = description;
|
||||||
}
|
}
|
||||||
|
|
@ -94,8 +92,7 @@
|
||||||
const imagesContainer = document.querySelector("[data-product-images]");
|
const imagesContainer = document.querySelector("[data-product-images]");
|
||||||
|
|
||||||
if (imagesContainer && product.images.edges.length > 0) {
|
if (imagesContainer && product.images.edges.length > 0) {
|
||||||
const productTitle =
|
const productTitle = isEnglish && product.titleEn?.value
|
||||||
isEnglish && product.titleEn?.value
|
|
||||||
? product.titleEn.value
|
? product.titleEn.value
|
||||||
: product.title;
|
: product.title;
|
||||||
|
|
||||||
|
|
@ -120,16 +117,12 @@
|
||||||
if (product.variants.edges.length <= 1) return;
|
if (product.variants.edges.length <= 1) return;
|
||||||
|
|
||||||
const firstVariant = product.variants.edges[0].node;
|
const firstVariant = product.variants.edges[0].node;
|
||||||
if (
|
if (!firstVariant.selectedOptions || firstVariant.selectedOptions.length === 0) return;
|
||||||
!firstVariant.selectedOptions ||
|
|
||||||
firstVariant.selectedOptions.length === 0
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const mainOption = firstVariant.selectedOptions[0];
|
const mainOption = firstVariant.selectedOptions[0];
|
||||||
const optionValues = new Set();
|
const optionValues = new Set();
|
||||||
|
|
||||||
product.variants.edges.forEach((edge) => {
|
product.variants.edges.forEach(edge => {
|
||||||
const variant = edge.node;
|
const variant = edge.node;
|
||||||
if (variant.selectedOptions && variant.selectedOptions[0]) {
|
if (variant.selectedOptions && variant.selectedOptions[0]) {
|
||||||
optionValues.add(variant.selectedOptions[0].value);
|
optionValues.add(variant.selectedOptions[0].value);
|
||||||
|
|
@ -144,15 +137,11 @@
|
||||||
if (!optionsContainer || !optionsList) return;
|
if (!optionsContainer || !optionsList) return;
|
||||||
|
|
||||||
const optionName = mainOption.name;
|
const optionName = mainOption.name;
|
||||||
const optionSlug = optionName.toLowerCase().replace(/\s+/g, "-");
|
const optionSlug = optionName.toLowerCase().replace(/\s+/g, '-');
|
||||||
|
|
||||||
optionsList.innerHTML = Array.from(optionValues)
|
optionsList.innerHTML = Array.from(optionValues).map((value) => {
|
||||||
.map((value) => {
|
const uniqueId = `${optionSlug}-${value.toLowerCase().replace(/\s+/g, '-')}`;
|
||||||
const uniqueId = `${optionSlug}-${value
|
const variant = product.variants.edges.find(e =>
|
||||||
.toLowerCase()
|
|
||||||
.replace(/\s+/g, "-")}`;
|
|
||||||
const variant = product.variants.edges.find(
|
|
||||||
(e) =>
|
|
||||||
e.node.selectedOptions && e.node.selectedOptions[0]?.value === value
|
e.node.selectedOptions && e.node.selectedOptions[0]?.value === value
|
||||||
)?.node;
|
)?.node;
|
||||||
const isAvailable = variant?.availableForSale || false;
|
const isAvailable = variant?.availableForSale || false;
|
||||||
|
|
@ -164,42 +153,36 @@
|
||||||
id="${uniqueId}"
|
id="${uniqueId}"
|
||||||
name="${optionSlug}"
|
name="${optionSlug}"
|
||||||
value="${value}"
|
value="${value}"
|
||||||
data-variant-id="${
|
data-variant-id="${variant ? variant.id.replace('gid://shopify/ProductVariant/', '') : ''}"
|
||||||
variant
|
${!isAvailable ? 'disabled' : ''}
|
||||||
? variant.id.replace("gid://shopify/ProductVariant/", "")
|
|
||||||
: ""
|
|
||||||
}"
|
|
||||||
${!isAvailable ? "disabled" : ""}
|
|
||||||
/>
|
/>
|
||||||
<label for="${uniqueId}">${value}</label>
|
<label for="${uniqueId}">${value}</label>
|
||||||
</li>
|
</li>
|
||||||
`;
|
`;
|
||||||
})
|
}).join('');
|
||||||
.join("");
|
|
||||||
|
|
||||||
optionsContainer.style.display = "block";
|
optionsContainer.style.display = 'block';
|
||||||
|
|
||||||
const radios = optionsList.querySelectorAll('input[type="radio"]');
|
const radios = optionsList.querySelectorAll('input[type="radio"]');
|
||||||
const addToCartBtn = document.querySelector("[data-shopify-add-to-cart]");
|
const addToCartBtn = document.querySelector("[data-shopify-add-to-cart]");
|
||||||
const buttonText = addToCartBtn?.querySelector("[data-button-text]");
|
const buttonText = addToCartBtn?.querySelector('[data-button-text]');
|
||||||
|
|
||||||
radios.forEach((radio) => {
|
radios.forEach(radio => {
|
||||||
radio.addEventListener("change", function () {
|
radio.addEventListener('change', function() {
|
||||||
const variantId = this.dataset.variantId;
|
const variantId = this.dataset.variantId;
|
||||||
|
|
||||||
if (addToCartBtn) {
|
if (addToCartBtn) {
|
||||||
addToCartBtn.dataset.variantId = variantId;
|
addToCartBtn.dataset.variantId = variantId;
|
||||||
addToCartBtn.removeAttribute("disabled");
|
addToCartBtn.removeAttribute('disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonText) {
|
if (buttonText) {
|
||||||
buttonText.textContent =
|
buttonText.textContent = addToCartBtn.dataset.defaultText || 'Ajouter au panier';
|
||||||
addToCartBtn.dataset.defaultText || "Ajouter au panier";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const allLi = optionsList.querySelectorAll("li");
|
const allLi = optionsList.querySelectorAll('li');
|
||||||
allLi.forEach((li) => li.classList.remove("is-selected"));
|
allLi.forEach(li => li.classList.remove('is-selected'));
|
||||||
this.closest("li").classList.add("is-selected");
|
this.closest('li').classList.add('is-selected');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -213,11 +196,10 @@
|
||||||
|
|
||||||
const hasMultipleVariants = product.variants.edges.length > 1;
|
const hasMultipleVariants = product.variants.edges.length > 1;
|
||||||
const firstVariant = product.variants.edges[0]?.node;
|
const firstVariant = product.variants.edges[0]?.node;
|
||||||
const hasOptions =
|
const hasOptions = firstVariant?.selectedOptions && firstVariant.selectedOptions.length > 0;
|
||||||
firstVariant?.selectedOptions && firstVariant.selectedOptions.length > 0;
|
|
||||||
|
|
||||||
const uniqueOptions = new Set();
|
const uniqueOptions = new Set();
|
||||||
product.variants.edges.forEach((edge) => {
|
product.variants.edges.forEach(edge => {
|
||||||
if (edge.node.selectedOptions && edge.node.selectedOptions[0]) {
|
if (edge.node.selectedOptions && edge.node.selectedOptions[0]) {
|
||||||
uniqueOptions.add(edge.node.selectedOptions[0].value);
|
uniqueOptions.add(edge.node.selectedOptions[0].value);
|
||||||
}
|
}
|
||||||
|
|
@ -225,11 +207,10 @@
|
||||||
const hasMultipleOptions = uniqueOptions.size > 1;
|
const hasMultipleOptions = uniqueOptions.size > 1;
|
||||||
|
|
||||||
if (hasMultipleVariants && hasOptions && hasMultipleOptions) {
|
if (hasMultipleVariants && hasOptions && hasMultipleOptions) {
|
||||||
addToCartBtn.setAttribute("disabled", "disabled");
|
addToCartBtn.setAttribute('disabled', 'disabled');
|
||||||
const buttonText = addToCartBtn.querySelector("[data-button-text]");
|
const buttonText = addToCartBtn.querySelector('[data-button-text]');
|
||||||
if (buttonText) {
|
if (buttonText) {
|
||||||
buttonText.textContent =
|
buttonText.textContent = addToCartBtn.dataset.textChooseOption || 'Choisissez une option';
|
||||||
addToCartBtn.dataset.textChooseOption || "Choisissez une option";
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const firstAvailableVariant = product.variants.edges.find(
|
const firstAvailableVariant = product.variants.edges.find(
|
||||||
|
|
@ -247,50 +228,44 @@
|
||||||
|
|
||||||
function updateMetaTags(product, isEnglish) {
|
function updateMetaTags(product, isEnglish) {
|
||||||
// Update title and description
|
// Update title and description
|
||||||
const title =
|
const title = isEnglish && product.titleEn?.value
|
||||||
isEnglish && product.titleEn?.value
|
|
||||||
? product.titleEn.value
|
? product.titleEn.value
|
||||||
: product.title;
|
: product.title;
|
||||||
const description =
|
const description = isEnglish && product.descriptionEn?.value
|
||||||
isEnglish && product.descriptionEn?.value
|
|
||||||
? product.descriptionEn.value
|
? product.descriptionEn.value
|
||||||
: product.description;
|
: product.description;
|
||||||
|
|
||||||
// Update Open Graph title
|
// Update Open Graph title
|
||||||
const ogTitle = document.getElementById("og-title");
|
const ogTitle = document.getElementById('og-title');
|
||||||
if (ogTitle) {
|
if (ogTitle) {
|
||||||
ogTitle.setAttribute("content", title);
|
ogTitle.setAttribute('content', title);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Open Graph description
|
// Update Open Graph description
|
||||||
const ogDescription = document.getElementById("og-description");
|
const ogDescription = document.getElementById('og-description');
|
||||||
if (ogDescription && description) {
|
if (ogDescription && description) {
|
||||||
const excerpt = description.substring(0, 160);
|
const excerpt = description.substring(0, 160);
|
||||||
ogDescription.setAttribute("content", excerpt);
|
ogDescription.setAttribute('content', excerpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Open Graph image
|
// Update Open Graph image
|
||||||
const ogImage = document.getElementById("og-image");
|
const ogImage = document.getElementById('og-image');
|
||||||
if (ogImage && product.images.edges.length > 0) {
|
if (ogImage && product.images.edges.length > 0) {
|
||||||
ogImage.setAttribute("content", product.images.edges[0].node.url);
|
ogImage.setAttribute('content', product.images.edges[0].node.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update product price
|
// Update product price
|
||||||
const ogPrice = document.getElementById("og-price");
|
const ogPrice = document.getElementById('og-price');
|
||||||
if (ogPrice) {
|
if (ogPrice) {
|
||||||
const price = parseFloat(
|
const price = parseFloat(product.priceRange.minVariantPrice.amount).toFixed(2);
|
||||||
product.priceRange.minVariantPrice.amount
|
ogPrice.setAttribute('content', price);
|
||||||
).toFixed(2);
|
|
||||||
ogPrice.setAttribute("content", price);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update availability
|
// Update availability
|
||||||
const ogAvailability = document.getElementById("og-availability");
|
const ogAvailability = document.getElementById('og-availability');
|
||||||
if (ogAvailability) {
|
if (ogAvailability) {
|
||||||
const availability = product.availableForSale
|
const availability = product.availableForSale ? 'in stock' : 'out of stock';
|
||||||
? "in stock"
|
ogAvailability.setAttribute('content', availability);
|
||||||
: "out of stock";
|
|
||||||
ogAvailability.setAttribute("content", availability);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update page title
|
// Update page title
|
||||||
|
|
@ -300,7 +275,7 @@
|
||||||
let metaDescription = document.querySelector('meta[name="description"]');
|
let metaDescription = document.querySelector('meta[name="description"]');
|
||||||
if (metaDescription && description) {
|
if (metaDescription && description) {
|
||||||
const excerpt = description.substring(0, 160);
|
const excerpt = description.substring(0, 160);
|
||||||
metaDescription.setAttribute("content", excerpt);
|
metaDescription.setAttribute('content', excerpt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -306,58 +306,6 @@ class ShopifyCart {
|
||||||
return cart;
|
return cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get existing cart by ID
|
|
||||||
*/
|
|
||||||
async getCart() {
|
|
||||||
if (!this.cartId) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const query = `
|
|
||||||
query getCart($cartId: ID!) {
|
|
||||||
cart(id: $cartId) {
|
|
||||||
id
|
|
||||||
checkoutUrl
|
|
||||||
lines(first: 10) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
id
|
|
||||||
quantity
|
|
||||||
merchandise {
|
|
||||||
... on ProductVariant {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
price {
|
|
||||||
amount
|
|
||||||
currencyCode
|
|
||||||
}
|
|
||||||
product {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await this.query(query, {
|
|
||||||
cartId: this.cartId
|
|
||||||
});
|
|
||||||
|
|
||||||
return data.cart;
|
|
||||||
} catch (error) {
|
|
||||||
// Cart might be expired or invalid
|
|
||||||
console.error('Error fetching cart:', error);
|
|
||||||
this.clearCart();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get checkout URL to redirect user
|
* Get checkout URL to redirect user
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
Title: Error
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
Template: default
|
|
||||||
|
|
@ -1,5 +1 @@
|
||||||
Title: Erreur
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
Uuid: kcrqkszqasludg2h
|
Uuid: kcrqkszqasludg2h
|
||||||
|
|
@ -25,56 +25,6 @@ return [
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
// English homepage
|
|
||||||
[
|
|
||||||
'pattern' => 'en',
|
|
||||||
'action' => function() {
|
|
||||||
$home = page('home');
|
|
||||||
if ($home) {
|
|
||||||
site()->visit($home, 'en');
|
|
||||||
return $home;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// English thanks page
|
|
||||||
[
|
|
||||||
'pattern' => 'en/thanks',
|
|
||||||
'action' => function() {
|
|
||||||
$thanks = page('thanks');
|
|
||||||
if ($thanks) {
|
|
||||||
site()->visit($thanks, 'en');
|
|
||||||
return $thanks;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// English error page
|
|
||||||
[
|
|
||||||
'pattern' => 'en/error',
|
|
||||||
'action' => function() {
|
|
||||||
$error = page('error');
|
|
||||||
if ($error) {
|
|
||||||
site()->visit($error, 'en');
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// French thanks page
|
|
||||||
[
|
|
||||||
'pattern' => 'thanks',
|
|
||||||
'action' => function() {
|
|
||||||
return page('thanks');
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// French error page
|
|
||||||
[
|
|
||||||
'pattern' => 'error',
|
|
||||||
'action' => function() {
|
|
||||||
return page('error');
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// French products (default)
|
// French products (default)
|
||||||
[
|
[
|
||||||
'pattern' => '(:any)',
|
'pattern' => '(:any)',
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,6 @@
|
||||||
const language = container.dataset.language || 'fr';
|
const language = container.dataset.language || 'fr';
|
||||||
const isEnglish = language === 'en';
|
const isEnglish = language === 'en';
|
||||||
|
|
||||||
function initStructuredData() {
|
|
||||||
if (typeof ShopifyCart === 'undefined') {
|
|
||||||
setTimeout(initStructuredData, 100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cart = new ShopifyCart({
|
const cart = new ShopifyCart({
|
||||||
domain: 'nv7cqv-bu.myshopify.com',
|
domain: 'nv7cqv-bu.myshopify.com',
|
||||||
storefrontAccessToken: 'dec3d35a2554384d149c72927d1cfd1b'
|
storefrontAccessToken: 'dec3d35a2554384d149c72927d1cfd1b'
|
||||||
|
|
@ -86,9 +80,5 @@
|
||||||
schemaScript.textContent = JSON.stringify(schema, null, 2);
|
schemaScript.textContent = JSON.stringify(schema, null, 2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize when ShopifyCart is available
|
|
||||||
initStructuredData();
|
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue