feat: fresh products

:%s
This commit is contained in:
lytrankieio123
2021-10-04 15:07:09 +07:00
parent 77a0432d07
commit 68f4e5beb5
8 changed files with 56 additions and 155 deletions

View File

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

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