mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 03:31:23 +00:00
✨ feat: feat fresh and featured products
:%s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { GetAllFacetsOperation } from './../types/facet';
|
||||
import type { ServerResponse } from 'http'
|
||||
import type { LoginOperation } from '../types/login'
|
||||
import type { GetAllPagesOperation, GetPageOperation } from '../types/page'
|
||||
@@ -156,23 +157,26 @@ export type Operations<P extends APIProvider> = {
|
||||
} & OperationOptions
|
||||
): Promise<T['data']>
|
||||
}
|
||||
|
||||
getAllFacets: {
|
||||
<T extends GetAllFacetsOperation>(opts: {
|
||||
variables?: T['variables']
|
||||
config?: P['config']
|
||||
preview?: boolean
|
||||
}): Promise<T['data']>
|
||||
|
||||
<T extends GetAllFacetsOperation>(
|
||||
opts: {
|
||||
variables?: T['variables']
|
||||
config?: P['config']
|
||||
preview?: boolean
|
||||
} & OperationOptions
|
||||
): Promise<T['data']>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// getAllFacets: {
|
||||
// <T extends GetAllFacetsOperation>(opts: {
|
||||
// variables?: T['variables']
|
||||
// config?: P['config']
|
||||
// preview?: boolean
|
||||
// }): Promise<T['data']>
|
||||
|
||||
// <T extends GetAllFacetsOperation>(
|
||||
// opts: {
|
||||
// variables?: T['variables']
|
||||
// config?: P['config']
|
||||
// preview?: boolean
|
||||
// } & OperationOptions
|
||||
// ): Promise<T['data']>
|
||||
// }
|
||||
|
||||
export type APIOperations<P extends APIProvider> = {
|
||||
[K in keyof Operations<P>]?: (ctx: OperationContext<P>) => Operations<P>[K]
|
||||
|
@@ -15,6 +15,7 @@ Adding a commerce provider means adding a new folder in `framework` with a folde
|
||||
- useSearch
|
||||
- getProduct
|
||||
- getAllProducts
|
||||
- getAllFacets
|
||||
- `wishlist`
|
||||
- useWishlist
|
||||
- useAddItem
|
||||
|
@@ -1,40 +1,14 @@
|
||||
|
||||
export type FacetOption = {
|
||||
__typename?: 'MultipleChoiceOption'
|
||||
id: string
|
||||
displayName: string
|
||||
values: FacetOptionValues[]
|
||||
}
|
||||
|
||||
export type FacetOptionValues = {
|
||||
label: string
|
||||
hexColors?: string[]
|
||||
}
|
||||
|
||||
export type FacetVariant = {
|
||||
id: string | number
|
||||
options: FacetOption[]
|
||||
availableForSale?: boolean
|
||||
}
|
||||
import { FacetValue } from './../../vendure/schema.d';
|
||||
|
||||
export type Facet = {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
descriptionHtml?: string
|
||||
sku?: string
|
||||
slug?: string
|
||||
path?: string
|
||||
images: FacetImage[]
|
||||
variants: FacetVariant[]
|
||||
price: FacetPrice
|
||||
options: FacetOption[]
|
||||
code: string
|
||||
values: FacetValue[]
|
||||
}
|
||||
|
||||
export type SearchFacetsBody = {
|
||||
search?: string
|
||||
categoryId?: string | number
|
||||
brandId?: string | number
|
||||
sort?: string
|
||||
locale?: string
|
||||
}
|
||||
@@ -63,17 +37,10 @@ export type FacetsSchema<T extends FacetTypes = FacetTypes> = {
|
||||
}
|
||||
}
|
||||
|
||||
export type GetAllFacetPathsOperation<
|
||||
T extends FacetTypes = FacetTypes
|
||||
> = {
|
||||
data: { facets: Pick<T['facet'], 'path'>[] }
|
||||
variables: { first?: number }
|
||||
}
|
||||
|
||||
export type GetAllFacetsOperation<T extends FacetTypes = FacetTypes> = {
|
||||
data: { facets: T['facet'][] }
|
||||
variables: {
|
||||
relevance?: 'featured' | 'best_selling' | 'newest'
|
||||
ids?: string[]
|
||||
first?: number
|
||||
}
|
||||
@@ -81,5 +48,5 @@ export type GetAllFacetsOperation<T extends FacetTypes = FacetTypes> = {
|
||||
|
||||
export type GetFacetOperation<T extends FacetTypes = FacetTypes> = {
|
||||
data: { facet?: T['facet'] }
|
||||
variables: { path: string; slug?: never } | { path?: never; slug: string }
|
||||
variables: { code: string; } | { code?: never; }
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import { FacetValueFilterInput, LogicalOperator, SearchResultSortParameter } from "@framework/schema"
|
||||
|
||||
export type ProductImage = {
|
||||
url: string
|
||||
alt?: string
|
||||
@@ -40,7 +42,6 @@ export type Product = {
|
||||
slug?: string
|
||||
path?: string
|
||||
images: ProductImage[]
|
||||
variants: ProductVariant[]
|
||||
price: ProductPrice
|
||||
options: ProductOption[]
|
||||
}
|
||||
@@ -79,17 +80,24 @@ export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
|
||||
|
||||
export type GetAllProductPathsOperation<
|
||||
T extends ProductTypes = ProductTypes
|
||||
> = {
|
||||
data: { products: Pick<T['product'], 'path'>[] }
|
||||
variables: { first?: number }
|
||||
}
|
||||
> = {
|
||||
data: { products: Pick<T['product'], 'path'>[] }
|
||||
variables: { first?: number }
|
||||
}
|
||||
|
||||
export type GetAllProductsOperation<T extends ProductTypes = ProductTypes> = {
|
||||
data: { products: T['product'][] }
|
||||
variables: {
|
||||
relevance?: 'featured' | 'best_selling' | 'newest'
|
||||
ids?: string[]
|
||||
first?: number
|
||||
term?: String
|
||||
facetValueIds?: string[]
|
||||
facetValueOperator?: LogicalOperator
|
||||
facetValueFilters?: FacetValueFilterInput[]
|
||||
collectionId?: string
|
||||
collectionSlug?: string
|
||||
groupByProduct?: Boolean
|
||||
take?: number
|
||||
skip?: number
|
||||
sort?: SearchResultSortParameter
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Facet } from '@commerce/types/facet'
|
||||
import { Provider, VendureConfig } from '../'
|
||||
import { GetAllFacetsQuery } from '../../schema'
|
||||
import { normalizeSearchResult } from '../../utils/normalize'
|
||||
import { getAllFacetsQuery } from '../../utils/queries/get-all-facets-query'
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
|
||||
export type FacetVariables = { first?: number }
|
||||
|
||||
@@ -38,7 +37,7 @@ export default function getAllFacetsOperation({
|
||||
})
|
||||
|
||||
return {
|
||||
facets: data.search.items.map((item) => normalizeSearchResult(item)),
|
||||
facets: data.facets.items,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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 }
|
||||
export type ProductVariables = { first?: number, facetValueIds?: string[] }
|
||||
|
||||
export default function getAllProductsOperation({
|
||||
commerce,
|
||||
@@ -30,6 +30,7 @@ export default function getAllProductsOperation({
|
||||
const variables = {
|
||||
input: {
|
||||
take: vars.first,
|
||||
facetValueIds: vars.facetValueIds,
|
||||
groupByProduct: true,
|
||||
},
|
||||
}
|
||||
|
4
framework/vendure/schema.d.ts
vendored
4
framework/vendure/schema.d.ts
vendored
@@ -3036,7 +3036,9 @@ export type CartFragment = { __typename?: 'Order' } & Pick<
|
||||
|
||||
export type SearchResultFragment = { __typename?: 'SearchResult' } & Pick<
|
||||
SearchResult,
|
||||
'productId' | 'productName' | 'description' | 'slug' | 'sku' | 'currencyCode'
|
||||
'productId' | 'sku' | 'productName' | 'description' | 'slug' | 'sku' | 'currencyCode'
|
||||
| 'productAsset' | 'price' | 'priceWithTax' | 'currencyCode'
|
||||
| 'collectionIds'
|
||||
> & {
|
||||
productAsset?: Maybe<
|
||||
{ __typename?: 'SearchResultAsset' } & Pick<
|
||||
|
@@ -3,18 +3,20 @@ 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' : ''
|
||||
return {
|
||||
id: item.productId,
|
||||
name: item.productName,
|
||||
description: item.description,
|
||||
slug: item.slug,
|
||||
path: item.slug,
|
||||
images: [{ url: item.productAsset?.preview + '?w=800&mode=crop' || '' }],
|
||||
variants: [],
|
||||
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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user