mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Small refactor
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
parent
2a32beb5cd
commit
735b0eded4
@ -7,12 +7,10 @@ import type {
|
|||||||
import { OCCategory, Category, Vendor, OCVendor } from '../types/site'
|
import { OCCategory, Category, Vendor, OCVendor } from '../types/site'
|
||||||
import {
|
import {
|
||||||
CatalogItemProduct,
|
CatalogItemProduct,
|
||||||
CatalogProduct,
|
|
||||||
CatalogProductVariant,
|
CatalogProductVariant,
|
||||||
ImageInfo,
|
ImageInfo,
|
||||||
Cart as OCCart,
|
Cart as OCCart,
|
||||||
CartItemEdge,
|
CartItemEdge,
|
||||||
CartItem,
|
|
||||||
} from '../../schema'
|
} from '../../schema'
|
||||||
import { Cart, LineItem } from '../types/cart'
|
import { Cart, LineItem } from '../types/cart'
|
||||||
|
|
||||||
@ -40,7 +38,7 @@ export function normalizeProduct(
|
|||||||
media,
|
media,
|
||||||
pricing,
|
pricing,
|
||||||
variants,
|
variants,
|
||||||
} = <CatalogProduct>product
|
} = product
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: productId ?? _id,
|
id: productId ?? _id,
|
||||||
@ -147,7 +145,7 @@ function mergeWithExistingOptions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const normalizeProductVariants = (
|
const normalizeProductVariants = (
|
||||||
variants: Array<CatalogProductVariant>
|
variants: CatalogProductVariant[]
|
||||||
): ProductVariant[] => {
|
): ProductVariant[] => {
|
||||||
return variants.reduce(
|
return variants.reduce(
|
||||||
(productVariants: ProductVariant[], variant: CatalogProductVariant) => {
|
(productVariants: ProductVariant[], variant: CatalogProductVariant) => {
|
||||||
@ -174,7 +172,9 @@ const normalizeProductVariants = (
|
|||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const normalizeProductOption = (variant: CatalogProductVariant) => {
|
const normalizeProductOption = (
|
||||||
|
variant: CatalogProductVariant
|
||||||
|
): ProductOption => {
|
||||||
const option = <ProductOption>{
|
const option = <ProductOption>{
|
||||||
__typename: 'MultipleChoiceOption',
|
__typename: 'MultipleChoiceOption',
|
||||||
id: variant._id,
|
id: variant._id,
|
||||||
@ -274,7 +274,7 @@ function normalizeLineItem(cartItemEdge: CartItemEdge): LineItem {
|
|||||||
variantTitle,
|
variantTitle,
|
||||||
quantity,
|
quantity,
|
||||||
productSlug,
|
productSlug,
|
||||||
} = <CartItem>cartItem
|
} = cartItem
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: _id,
|
id: _id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user