Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow purchases of digital merch #10751

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/templates/merch/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 17 additions & 13 deletions src/templates/merch/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,23 @@ function getVariants(variants: StorefrontProductVariantsEdges): StorefrontProduc
async function assignBrilliantQuantities(variants: StorefrontProductVariantNode[]): Promise<void> {
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
})
}
})
)
}