mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 03:31:23 +00:00
add product to cart
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { CurrencyCode } from './../../vendure/schema.d';
|
||||
import { FacetValueFilterInput, LogicalOperator, SearchResultSortParameter } from "@framework/schema"
|
||||
|
||||
export type ProductImage = {
|
||||
@@ -46,6 +47,21 @@ export type Product = {
|
||||
options: ProductOption[]
|
||||
}
|
||||
|
||||
export type ProductCard = {
|
||||
id: string
|
||||
name: string
|
||||
slug?: string
|
||||
imageSrc: string
|
||||
price: number
|
||||
currencyCode: CurrencyCode
|
||||
oldPrice?: number,
|
||||
discount?: number
|
||||
weight?: number
|
||||
// TODO: collection
|
||||
category?: string,
|
||||
isNotSell?: boolean
|
||||
}
|
||||
|
||||
export type SearchProductsBody = {
|
||||
search?: string
|
||||
categoryId?: string | number
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user