Correct Variant Added to Cart

This commit is contained in:
Belen Curcio
2021-01-11 16:16:00 -03:00
parent 9bbd7feed0
commit 287e690495
7 changed files with 63 additions and 78 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -46,7 +46,7 @@ export function extendHook(
const response = useCommerceWishlist(
defaultOpts,
[
['customerId', customer?.entityId],
['customerId', customer?.id],
['includeProducts', includeProducts],
],
customFetcher,

View File

@@ -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
}