From 385705d48d37d0542b7386710cfd133ce22cbaf8 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 22 Jun 2024 01:45:47 +1000 Subject: [PATCH] Fix adding variants to cart --- pages/merch.tsx | 8 +++++++- scripts/merch.ts | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pages/merch.tsx b/pages/merch.tsx index 4f1c880..55b67a5 100644 --- a/pages/merch.tsx +++ b/pages/merch.tsx @@ -51,6 +51,12 @@ export const getServerSideProps = async () => { product.price; }); + variants.forEach((variant: Variant) => { + variant.price = + prices.find((price: Price) => price.id === variant.price.id) ?? + variant.price; + }); + const repo: Repo = { products, variants }; return { props: { repo } }; }; @@ -388,7 +394,7 @@ const Merch = ({ name: variant.productName, images: variant.imageURLs, }, - price: product.price, + price: variant.price, qty, }); }); diff --git a/scripts/merch.ts b/scripts/merch.ts index 5bb7bc5..daf6134 100644 --- a/scripts/merch.ts +++ b/scripts/merch.ts @@ -33,7 +33,7 @@ export type Variant = { productName: string; colour: ProductColour; size: ProductSize; - + price: Price; id: string; imageURLs: string[]; }; @@ -121,6 +121,7 @@ export const getAllProductsAndVariants = async (stripe: Stripe) => { size: toProductSizeMap.get(variantSize) ?? ProductSize.UNKNOWN, id: variant.id, imageURLs: variant.images, + price: { id: variant.default_price?.toString() ?? "" }, }); });