add product to cart

This commit is contained in:
DatNguyen
2021-10-06 08:35:55 +07:00
9 changed files with 103 additions and 198 deletions

View File

@@ -1,24 +1,23 @@
import { Product } from '@commerce/types/product'
import { Product, ProductCard } from '@commerce/types/product'
import { Cart } from '@commerce/types/cart'
import { CartFragment, SearchResultFragment } from '../schema'
export function normalizeSearchResult(item: SearchResultFragment): Product {
const imageUrl = item.productAsset?.preview ? item.productAsset?.preview + '?w=800&mode=crop' : ''
export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
return {
id: item.productId,
name: item.productName,
description: item.description,
slug: item.slug,
path: item.slug,
images: imageUrl ? [{ url: imageUrl }] : [],
price: {
// TODO: check price
value: (item.priceWithTax as any).min / 100,
currencyCode: item.currencyCode,
},
// TODO: check product option
options: [],
sku: item.sku,
imageSrc: item.productAsset?.preview ? item.productAsset?.preview + '?w=800&mode=crop' : '',
price: (item.priceWithTax as any).min / 100,
currencyCode: item.currencyCode,
// TODO:
// oldPrice: item.price
// discount
// isNotSell
// weight
// category
}
}