viewed prodyct

This commit is contained in:
DatNguyen
2021-10-15 11:18:29 +07:00
parent 98265d0f2b
commit 14fa653713
12 changed files with 113 additions and 18 deletions

View File

@@ -36,6 +36,7 @@ export default function getProductOperation({
})),
variants: product.variants.map((v) => ({
id: v.id,
name:v.name,
options: v.options.map((o) => ({
// This __typename property is required in order for the correct
// variant selection to work, see `components/product/helpers.ts`

View File

@@ -3303,7 +3303,7 @@ export type GetProductQuery = { __typename?: 'Query' } & {
variants: Array<
{ __typename?: 'ProductVariant' } & Pick<
ProductVariant,
'id' | 'priceWithTax' | 'currencyCode' | 'price'
'id' | 'priceWithTax' | 'currencyCode' | 'price' | "name"
> & {
options: Array<
{ __typename?: 'ProductOption' } & Pick<

View File

@@ -1,5 +1,5 @@
import { Cart } from '@commerce/types/cart'
import { ProductCard } from '@commerce/types/product'
import { ProductCard, Product } from '@commerce/types/product'
import { CartFragment, SearchResultFragment } from '../schema'
export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
@@ -57,3 +57,18 @@ export function normalizeCart(order: CartFragment): Cart {
})),
}
}
export function normalizeProductCard(product: Product): ProductCard {
return {
id: product.id,
name: product.name,
slug: product.slug,
imageSrc: product.images[0].url,
price: product.price,
currencyCode: product.currencyCode,
productVariantId: product.variants?.[0].id.toString(),
productVariantName:product.variants?.[0].name,
facetValueIds: product.facetValueIds,
collectionIds: product.collectionIds,
}
}

View File

@@ -12,6 +12,7 @@ export const getProductQuery = /* GraphQL */ `
}
variants {
id
name
priceWithTax
currencyCode
options {