mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 03:31:23 +00:00
bug: fix favorite products
This commit is contained in:
@@ -5,7 +5,7 @@ import { normalizeSearchResult } from '../../utils/normalize'
|
||||
import { getAllProductsQuery } from '../../utils/queries/get-all-products-query'
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
|
||||
export type ProductVariables = { first?: number, facetValueIds?: string[] }
|
||||
export type ProductVariables = { first?: number, facetValueIds?: string[],collectionSlug?:string }
|
||||
|
||||
export default function getAllProductsOperation({
|
||||
commerce,
|
||||
@@ -31,13 +31,13 @@ export default function getAllProductsOperation({
|
||||
input: {
|
||||
take: vars.first,
|
||||
facetValueIds: vars.facetValueIds,
|
||||
collectionSlug: vars.collectionSlug,
|
||||
groupByProduct: true,
|
||||
},
|
||||
}
|
||||
const { data } = await config.fetch<GetAllProductsQuery>(query, {
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
products: data.search.items.map((item) => normalizeSearchResult(item)),
|
||||
totalItems: data.search.totalItems as number,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Cart } from '@commerce/types/cart'
|
||||
import { ProductCard } from '@commerce/types/product'
|
||||
import { CartFragment, SearchResultFragment } from '../schema'
|
||||
import { CartFragment, SearchResultFragment,Favorite,ActiveCustomerQuery } from '../schema'
|
||||
|
||||
export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
return {
|
||||
@@ -21,6 +21,18 @@ export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeFavoriteProductResult(item: Favorite) {
|
||||
return {
|
||||
id: item.product.id,
|
||||
name: item.product.name,
|
||||
slug: item.product.slug,
|
||||
imageSrc: item.product.assets[0].preview ? item.product.assets[0].preview + '?w=800&mode=crop' : '',
|
||||
price: item.product.variants[0].priceWithTax as number / 100,
|
||||
currencyCode: item.product.variants[0].currencyCode,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function normalizeCart(order: CartFragment): Cart {
|
||||
return {
|
||||
id: order.id.toString(),
|
||||
|
@@ -16,7 +16,8 @@ query activeCustomer($options: FavoriteListOptions) {
|
||||
preview
|
||||
}
|
||||
variants{
|
||||
price
|
||||
priceWithTax
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user