From 76b28c079d7a813611b3afdf8f2171c121405c8f Mon Sep 17 00:00:00 2001 From: Eli Kinsey Date: Fri, 21 Feb 2025 09:05:07 -0800 Subject: [PATCH] allow purchases of digital merch --- src/templates/merch/Checkout.tsx | 3 +++ src/templates/merch/hooks.ts | 30 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/templates/merch/Checkout.tsx b/src/templates/merch/Checkout.tsx index d1fcb86bcea6..3ee7836d782b 100644 --- a/src/templates/merch/Checkout.tsx +++ b/src/templates/merch/Checkout.tsx @@ -64,6 +64,9 @@ export function Checkout(props: CheckoutProps): React.ReactElement { if (cart === null) return for (const item of cartItems) { + if (item.product.tags.includes('digital')) { + continue + } // first check if it's available for sale. If not, then add to the list // with flag for removal from cart const quantityAvailable = await getAvailableQuantity(item) diff --git a/src/templates/merch/hooks.ts b/src/templates/merch/hooks.ts index 18432550237c..e125bbe387e0 100644 --- a/src/templates/merch/hooks.ts +++ b/src/templates/merch/hooks.ts @@ -192,19 +192,23 @@ function getVariants(variants: StorefrontProductVariantsEdges): StorefrontProduc async function assignBrilliantQuantities(variants: StorefrontProductVariantNode[]): Promise { await Promise.all( variants.map((v) => { - return fetch( - `${process.env.GATSBY_SQUEAK_API_HOST}/api/brilliant/inventory/${ - v.id.split('gid://shopify/ProductVariant/')[1] - }` - ) - .then((res) => res.json()) - .then((data) => { - v.brilliantQuantity = data?.quantity || 0 - }) - .catch((err) => { - console.error('Error fetching quantity:', err) - v.brilliantQuantity = 0 - }) + if (v.product.tags.includes('digital')) { + v.brilliantQuantity = v.quantityAvailable + } else { + return fetch( + `${process.env.GATSBY_SQUEAK_API_HOST}/api/brilliant/inventory/${ + v.id.split('gid://shopify/ProductVariant/')[1] + }` + ) + .then((res) => res.json()) + .then((data) => { + v.brilliantQuantity = data?.quantity || 0 + }) + .catch((err) => { + console.error('Error fetching quantity:', err) + v.brilliantQuantity = 0 + }) + } }) ) }