diff --git a/src/components/solid/ProductFiltersForm.astro b/src/components/solid/ProductFiltersForm.astro index 96130069..f2b47842 100644 --- a/src/components/solid/ProductFiltersForm.astro +++ b/src/components/solid/ProductFiltersForm.astro @@ -1,7 +1,9 @@ --- +/* Dynamic Tea Bag categorization logic has been commented out */ + import subset from "@utils/shared/subset"; import ProductFiltersForm from "@solid/ProductFiltersForm"; -import Products, { teaBag, teaBagVariants } from "@store/Products"; +// import Products, { teaBag, teaBagVariants } from "@store/Products"; let { locale, @@ -14,15 +16,15 @@ let { recurData = subset(recurData, ["text_all_tea_variants", "text_all_tea_sizes"]); -const teaBagVariant = productVariants.data.find( - ({ attributes }) => attributes.is_tea_bag, -); +// const teaBagVariant = productVariants.data.find( +// ({ attributes }) => attributes.is_tea_bag, +// ); -const teaBagVariantLocalizedTitle = [ - teaBagVariant, - ...teaBagVariant.attributes.localizations.data, -].find(({ attributes }) => attributes.locale.substring(0, 2) === locale) - .attributes.Title; +// const teaBagVariantLocalizedTitle = [ +// teaBagVariant, +// ...teaBagVariant.attributes.localizations.data, +// ].find(({ attributes }) => attributes.locale.substring(0, 2) === locale) +// .attributes.Title; [productSizes, productVariants] = [productSizes, productVariants].map( ({ data }, i) => ({ @@ -37,41 +39,53 @@ const teaBagVariantLocalizedTitle = [ if (localizedTitle) { const { Title, is_tea_bag, is_tea_bag_subvariant } = attributes; - if (is_tea_bag_subvariant) { - localizedTitle = - teaBagVariantLocalizedTitle + "- " + localizedTitle; - } - - const products = !is_tea_bag - ? attributes.products.data.map(({ attributes }) => attributes) - : Products.get("en | " + teaBag) - .map(([, variants]) => variants.map(([, variant]) => variant)) - .flat(); - - const rawAvailableCombinations = products.map((attributes) => { - const variantType = i === 0 ? "variant" : "size", - variant = attributes[variantType]; - - try { - return variant.data.attributes.Title; - } catch (error) { - throw new Error( - `\x1b[31m${attributes.Title} is missing '${variantType}'\x1b[0m`, - ); - } - }); - - if ( - i === 0 && - rawAvailableCombinations.some((variant) => - teaBagVariants.includes(variant), - ) - ) { - rawAvailableCombinations.push(teaBag); - } + // if (is_tea_bag_subvariant) { + // localizedTitle = + // teaBagVariantLocalizedTitle + "- " + localizedTitle; + // } + + // const products = !is_tea_bag + // ? attributes.products.data.map(({ attributes }) => attributes) + // : Products.get("en | " + teaBag) + // .map(([, variants]) => variants.map(([, variant]) => variant)) + // .flat(); + + // const rawAvailableCombinations = products.map((attributes) => { + // const variantType = i === 0 ? "variant" : "size", + // variant = attributes[variantType]; + + // try { + // return variant.data.attributes.Title; + // } catch (error) { + // throw new Error( + // `\x1b[31m${attributes.Title} is missing '${variantType}'\x1b[0m`, + // ); + // } + // }); + + // if ( + // i === 0 && + // rawAvailableCombinations.some((variant) => + // teaBagVariants.includes(variant), + // ) + // ) { + // rawAvailableCombinations.push(teaBag); + // } + + // const availableCombinations = JSON.stringify( + // Array.from(new Set(rawAvailableCombinations)), + // ); const availableCombinations = JSON.stringify( - Array.from(new Set(rawAvailableCombinations)), + Array.from( + new Set( + attributes.products.data.map( + ({ attributes }) => + attributes[i === 0 ? "variant" : "size"].data.attributes + .Title, + ), + ), + ), ); return { @@ -86,15 +100,15 @@ const teaBagVariantLocalizedTitle = [ a.localizedTitle.localeCompare(b.localizedTitle, locale, { numeric: true, }), - ) - .map((data) => { - data.localizedTitle = data.localizedTitle.replace( - teaBagVariantLocalizedTitle + "-", - "-", - ); - - return data; - }), + ), + // .map((data) => { + // data.localizedTitle = data.localizedTitle.replace( + // teaBagVariantLocalizedTitle + "-", + // "-", + // ); + + // return data; + // }), }), ); --- diff --git a/src/store/Products.ts b/src/store/Products.ts index 8d59f62b..13786319 100644 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -1,3 +1,5 @@ +/* Dynamic Tea Bag categorization logic has been commented out */ + import CMS from "@store/CMS"; const catalog = CMS.get("catalog").data.attributes, @@ -32,16 +34,16 @@ export const variantsOrder = [ ), ]; -export const teaBag = productVariants.data.find( - ({ attributes }) => attributes.is_tea_bag, -).attributes.Title; +// export const teaBag = productVariants.data.find( +// ({ attributes }) => attributes.is_tea_bag, +// ).attributes.Title; -export const teaBagVariants = [ - teaBag, - ...productVariants.data - .filter(({ attributes }) => attributes.is_tea_bag_subvariant) - .map(({ attributes }) => attributes.Title), -]; +// export const teaBagVariants = [ +// teaBag, +// ...productVariants.data +// .filter(({ attributes }) => attributes.is_tea_bag_subvariant) +// .map(({ attributes }) => attributes.Title), +// ]; const ProxyHandler = { get: (target, key) => { @@ -108,19 +110,19 @@ const allProducts = catalog.Products.flatMap( ]); if (variant) { - if (variant !== teaBag) { - variantsPerProduct[locale + " | " + variant].push([ - size || "None", - attributes, - ]); - } - - if (teaBagVariants.includes(variant)) { - variantsPerProduct[locale + " | " + teaBag].push([ - variant + " | " + size, - attributes, - ]); - } + // if (variant !== teaBag) { + variantsPerProduct[locale + " | " + variant].push([ + size || "None", + attributes, + ]); + // } + + // if (teaBagVariants.includes(variant)) { + // variantsPerProduct[locale + " | " + teaBag].push([ + // variant + " | " + size, + // attributes, + // ]); + // } } if (size) { @@ -129,20 +131,20 @@ const allProducts = catalog.Products.flatMap( attributes, ]); - if (teaBagVariants.includes(variant)) { - variantsPerProduct[locale + " | " + size].push([ - teaBag, - attributes, - ]); - } + // if (teaBagVariants.includes(variant)) { + // variantsPerProduct[locale + " | " + size].push([ + // teaBag, + // attributes, + // ]); + // } } if (variant && size) { Products[locale + " | " + variant + " | " + size].push(attributes); - if (teaBagVariants.includes(variant)) { - Products[locale + " | " + teaBag + " | " + size].push(attributes); - } + // if (teaBagVariants.includes(variant)) { + // Products[locale + " | " + teaBag + " | " + size].push(attributes); + // } } attributes.names = names; diff --git a/window.d.ts b/window.d.ts index ceaf0f48..96c8bc77 100644 --- a/window.d.ts +++ b/window.d.ts @@ -111,7 +111,6 @@ declare global { input: HTMLInputElement, ) => void; // defined in CartOverlay.astro - removeTopNotification: (notification: HTMLElement) => void; // defined in NotificationAnimations.astro slideOutTopNotification: (notification: HTMLElement) => void; // defined in NotificationAnimations.astro hideAllPaymentInfo: () => void; // defined in CheckoutPayment.astro