Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafidMuhymin committed Aug 25, 2024
2 parents 5dc42b8 + 50162bc commit f014cae
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 83 deletions.
116 changes: 65 additions & 51 deletions src/components/solid/ProductFiltersForm.astro
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) => ({
Expand All @@ -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 {
Expand All @@ -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;
// }),
}),
);
---
Expand Down
64 changes: 33 additions & 31 deletions src/store/Products.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f014cae

Please sign in to comment.