mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Correct Variant Added to Cart
This commit is contained in:
@@ -21,7 +21,7 @@ export type ProductsHandlers = {
|
||||
|
||||
const METHODS = ['GET']
|
||||
|
||||
// TODO: a complete implementation should have schema validation for `req.body`
|
||||
// TODO(lf): a complete implementation should have schema validation for `req.body`
|
||||
const productsApi: BigcommerceApiHandler<
|
||||
SearchProductsData,
|
||||
ProductsHandlers
|
||||
|
@@ -1,5 +1,19 @@
|
||||
import { Product as BCProduct } from '@framework/schema'
|
||||
|
||||
function productOptionNormalize({
|
||||
node: {
|
||||
entityId,
|
||||
values: { edges },
|
||||
...rest
|
||||
},
|
||||
}: any) {
|
||||
return {
|
||||
id: entityId,
|
||||
values: edges.map(({ node }: any) => node),
|
||||
...rest,
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeProduct(productNode: BCProduct): Product {
|
||||
const {
|
||||
entityId: id,
|
||||
@@ -10,6 +24,7 @@ export function normalizeProduct(productNode: BCProduct): Product {
|
||||
path,
|
||||
id: _,
|
||||
options: _0,
|
||||
brand,
|
||||
...rest
|
||||
} = productNode
|
||||
|
||||
@@ -27,26 +42,21 @@ export function normalizeProduct(productNode: BCProduct): Product {
|
||||
)
|
||||
: [],
|
||||
variants: variants.edges
|
||||
? variants.edges.map(({ node: { entityId, ...rest } }: any) => ({
|
||||
id: entityId,
|
||||
...rest,
|
||||
}))
|
||||
: [],
|
||||
options: productOptions.edges
|
||||
? productOptions.edges.map(
|
||||
({
|
||||
node: {
|
||||
entityId,
|
||||
values: { edges },
|
||||
...rest
|
||||
},
|
||||
}: any) => ({
|
||||
? variants.edges.map(
|
||||
({ node: { entityId, productOptions, ...rest } }: any) => ({
|
||||
id: entityId,
|
||||
values: edges.map(({ node }: any) => node),
|
||||
options: productOptions.edges.map(productOptionNormalize),
|
||||
...rest,
|
||||
})
|
||||
)
|
||||
: [],
|
||||
options: productOptions.edges
|
||||
? productOptions.edges.map(productOptionNormalize)
|
||||
: [],
|
||||
brand: {
|
||||
id: brand?.entityId,
|
||||
...brand,
|
||||
},
|
||||
price: {
|
||||
value: prices?.price.value,
|
||||
currencyCode: prices?.price.currencyCode,
|
||||
|
@@ -46,7 +46,7 @@ export function extendHook(
|
||||
const response = useCommerceWishlist(
|
||||
defaultOpts,
|
||||
[
|
||||
['customerId', customer?.entityId],
|
||||
['customerId', customer?.id],
|
||||
['includeProducts', includeProducts],
|
||||
],
|
||||
customFetcher,
|
||||
|
7
framework/types.d.ts
vendored
7
framework/types.d.ts
vendored
@@ -31,6 +31,7 @@ interface ProductImage {
|
||||
|
||||
interface ProductVariant {
|
||||
id: string | number
|
||||
options: ProductOption[]
|
||||
}
|
||||
|
||||
interface ProductPrice {
|
||||
@@ -51,21 +52,17 @@ interface Wishlist extends Entity {
|
||||
|
||||
interface Order {}
|
||||
|
||||
interface Customer extends Entity {
|
||||
[prop: string]: any
|
||||
}
|
||||
interface Customer extends Entity {}
|
||||
|
||||
type UseCustomerResponse = {
|
||||
customer: Customer
|
||||
} | null
|
||||
|
||||
interface Category extends Entity {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
interface Brand extends Entity {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user