mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
Merge branch 'release-stable' of https://github.com/KieIO/grocery-vercel-commerce into feature/m1-get-product-detail
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import type { APIProvider, CommerceAPIConfig } from '@commerce/api'
|
||||
import type { CommerceAPIConfig } from '@commerce/api'
|
||||
import { CommerceAPI, getCommerceApi as commerceApi } from '@commerce/api'
|
||||
import fetchGraphqlApi from './utils/fetch-graphql-api'
|
||||
|
||||
import login from './operations/login'
|
||||
import getAllFacets from './operations/get-all-facets'
|
||||
import getAllCollections from './operations/get-all-collection'
|
||||
import getAllPages from './operations/get-all-pages'
|
||||
import getPage from './operations/get-page'
|
||||
import getSiteInfo from './operations/get-site-info'
|
||||
import getCustomerWishlist from './operations/get-customer-wishlist'
|
||||
import getAllProductPaths from './operations/get-all-product-paths'
|
||||
import getAllProducts from './operations/get-all-products'
|
||||
import getCustomerWishlist from './operations/get-customer-wishlist'
|
||||
import getPage from './operations/get-page'
|
||||
import getProduct from './operations/get-product'
|
||||
import getSiteInfo from './operations/get-site-info'
|
||||
import login from './operations/login'
|
||||
import fetchGraphqlApi from './utils/fetch-graphql-api'
|
||||
|
||||
|
||||
export interface VendureConfig extends CommerceAPIConfig {}
|
||||
|
||||
@@ -40,6 +42,8 @@ const operations = {
|
||||
getAllProductPaths,
|
||||
getAllProducts,
|
||||
getProduct,
|
||||
getAllFacets,
|
||||
getAllCollections,
|
||||
}
|
||||
|
||||
export const provider = { config, operations }
|
||||
|
45
framework/vendure/api/operations/get-all-collection.ts
Normal file
45
framework/vendure/api/operations/get-all-collection.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Collection } from '@commerce/types/collection'
|
||||
import { Provider, VendureConfig } from '..'
|
||||
import { GetAllCollectionsQuery } from '../../schema'
|
||||
import { getAllCollectionsQuery } from '../../utils/queries/get-all-collections-query'
|
||||
|
||||
export type CollectionVariables = { first?: number }
|
||||
|
||||
export default function getAllCollectionsOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
async function getAllCollections(opts?: {
|
||||
variables?: CollectionVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
}): Promise<{ collections: Collection[] }>
|
||||
|
||||
async function getAllCollections({
|
||||
query = getAllCollectionsQuery,
|
||||
variables: { ...vars } = {},
|
||||
config: cfg,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: CollectionVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ collections: Collection[] | any[] }> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
const variables = {
|
||||
input: {
|
||||
take: vars.first,
|
||||
groupByCollection: true,
|
||||
},
|
||||
}
|
||||
const { data } = await config.fetch<GetAllCollectionsQuery>(query, {
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
collections: data.collections.items,
|
||||
}
|
||||
}
|
||||
|
||||
return getAllCollections
|
||||
}
|
45
framework/vendure/api/operations/get-all-facets.ts
Normal file
45
framework/vendure/api/operations/get-all-facets.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Facet } from '@commerce/types/facet'
|
||||
import { Provider, VendureConfig } from '../'
|
||||
import { GetAllFacetsQuery } from '../../schema'
|
||||
import { getAllFacetsQuery } from '../../utils/queries/get-all-facets-query'
|
||||
|
||||
export type FacetVariables = { first?: number }
|
||||
|
||||
export default function getAllFacetsOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
async function getAllFacets(opts?: {
|
||||
variables?: FacetVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
}): Promise<{ facets: Facet[] }>
|
||||
|
||||
async function getAllFacets({
|
||||
query = getAllFacetsQuery,
|
||||
variables: { ...vars } = {},
|
||||
config: cfg,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: FacetVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ facets: Facet[] | any[] }> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
const variables = {
|
||||
input: {
|
||||
take: vars.first,
|
||||
groupByFacet: true,
|
||||
},
|
||||
}
|
||||
const { data } = await config.fetch<GetAllFacetsQuery>(query, {
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
facets: data.facets.items,
|
||||
}
|
||||
}
|
||||
|
||||
return getAllFacets
|
||||
}
|
@@ -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,
|
||||
},
|
||||
}
|
||||
|
67
framework/vendure/schema.d.ts
vendored
67
framework/vendure/schema.d.ts
vendored
@@ -1,3 +1,4 @@
|
||||
import { FacetValue } from './schema.d';
|
||||
export type Maybe<T> = T | null
|
||||
export type Exact<T extends { [key: string]: unknown }> = {
|
||||
[K in keyof T]: T[K]
|
||||
@@ -93,6 +94,10 @@ export type QueryProductsArgs = {
|
||||
options?: Maybe<ProductListOptions>
|
||||
}
|
||||
|
||||
export type QueryFacetsArgs = {
|
||||
options?: Maybe<FacetListOptions>
|
||||
}
|
||||
|
||||
export type QuerySearchArgs = {
|
||||
input: SearchInput
|
||||
}
|
||||
@@ -2727,6 +2732,13 @@ export type ProductListOptions = {
|
||||
filter?: Maybe<ProductFilterParameter>
|
||||
}
|
||||
|
||||
export type FacetListOptions = {
|
||||
skip?: Maybe<Scalars['Int']>
|
||||
take?: Maybe<Scalars['Int']>
|
||||
sort?: Maybe<FacetSortParameter>
|
||||
filter?: Maybe<FacetFilterParameter>
|
||||
}
|
||||
|
||||
export type UpdateOrderItemsResult =
|
||||
| Order
|
||||
| OrderModificationError
|
||||
@@ -2884,6 +2896,23 @@ export type ProductVariantSortParameter = {
|
||||
discountPrice?: Maybe<SortOrder>
|
||||
}
|
||||
|
||||
|
||||
export type FacetFilterParameter = {
|
||||
createdAt?: Maybe<DateOperators>
|
||||
updatedAt?: Maybe<DateOperators>
|
||||
languageCode?: Maybe<StringOperators>
|
||||
name?: Maybe<StringOperators>
|
||||
code?: Maybe<StringOperators>
|
||||
}
|
||||
|
||||
export type FacetSortParameter = {
|
||||
id?: Maybe<SortOrder>
|
||||
createdAt?: Maybe<SortOrder>
|
||||
updatedAt?: Maybe<SortOrder>
|
||||
name?: Maybe<SortOrder>
|
||||
code?: Maybe<SortOrder>
|
||||
}
|
||||
|
||||
export type CustomerFilterParameter = {
|
||||
createdAt?: Maybe<DateOperators>
|
||||
updatedAt?: Maybe<DateOperators>
|
||||
@@ -3008,7 +3037,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' | 'facetValueIds' | 'collectionIds'
|
||||
> & {
|
||||
productAsset?: Maybe<
|
||||
{ __typename?: 'SearchResultAsset' } & Pick<
|
||||
@@ -3192,6 +3223,40 @@ export type GetAllProductsQuery = { __typename?: 'Query' } & {
|
||||
}
|
||||
}
|
||||
|
||||
export type GetAllFacetsQuery = { __typename?: 'Query' } & {
|
||||
facets: { __typename?: 'FacetList' } & {
|
||||
items: Array<
|
||||
{ __typename?: 'Facet' } & Pick<
|
||||
Facet,
|
||||
'id' | 'name' | 'code'
|
||||
> & {
|
||||
parent?: Maybe<{ __typename?: 'Facet' } & Pick<Facet, 'id'>>
|
||||
children?: Maybe<
|
||||
Array<{ __typename?: 'Facet' } & Pick<Facet, 'id'>>
|
||||
>
|
||||
}
|
||||
>,
|
||||
'totalItems'
|
||||
}
|
||||
}
|
||||
|
||||
export type GetAllCollectionsQuery = { __typename?: 'Query' } & {
|
||||
collections: { __typename?: 'CollectionList' } & {
|
||||
items: Array<
|
||||
{ __typename?: 'Collection' } & Pick<
|
||||
Collection,
|
||||
'id' | 'name' | 'slug'
|
||||
> & {
|
||||
parent?: Maybe<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
|
||||
children?: Maybe<
|
||||
Array<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
|
||||
>
|
||||
}
|
||||
>,
|
||||
'totalItems'
|
||||
}
|
||||
}
|
||||
|
||||
export type ActiveOrderQueryVariables = Exact<{ [key: string]: never }>
|
||||
|
||||
export type ActiveOrderQuery = { __typename?: 'Query' } & {
|
||||
|
@@ -19,6 +19,8 @@ export const searchResultFragment = /* GraphQL */ `
|
||||
min
|
||||
max
|
||||
}
|
||||
}
|
||||
},
|
||||
facetValueIds,
|
||||
collectionIds,
|
||||
}
|
||||
`
|
||||
|
@@ -1,22 +1,23 @@
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { Cart } from '@commerce/types/cart'
|
||||
import { ProductCard } from '@commerce/types/product'
|
||||
import { CartFragment, SearchResultFragment } from '../schema'
|
||||
|
||||
export function normalizeSearchResult(item: SearchResultFragment): Product {
|
||||
export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
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: [],
|
||||
price: {
|
||||
value: (item.priceWithTax as any).min / 100,
|
||||
currencyCode: item.currencyCode,
|
||||
},
|
||||
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,
|
||||
facetValueIds: item.facetValueIds,
|
||||
collectionIds: item.collectionIds,
|
||||
|
||||
// TODO:
|
||||
// oldPrice: item.price
|
||||
// discount
|
||||
// isNotSell
|
||||
// weight
|
||||
}
|
||||
}
|
||||
|
||||
|
12
framework/vendure/utils/queries/get-all-collections-query.ts
Normal file
12
framework/vendure/utils/queries/get-all-collections-query.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const getAllCollectionsQuery = /* GraphQL */ `
|
||||
query collections ($options: CollectionListOptions) {
|
||||
collections (options: $options){
|
||||
totalItems,
|
||||
items {
|
||||
id
|
||||
name
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
17
framework/vendure/utils/queries/get-all-facets-query.ts
Normal file
17
framework/vendure/utils/queries/get-all-facets-query.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export const getAllFacetsQuery = /* GraphQL */ `
|
||||
query facets ($options: FacetListOptions) {
|
||||
facets (options: $options){
|
||||
totalItems,
|
||||
items {
|
||||
id
|
||||
name
|
||||
code
|
||||
values {
|
||||
id
|
||||
name
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
@@ -19,3 +19,13 @@ export const getCollectionsQuery = /* GraphQL */ `
|
||||
}
|
||||
}
|
||||
`
|
||||
export const getCollectionsNameQuery = /* GraphQL */ `
|
||||
query getCollections {
|
||||
collections{
|
||||
items{
|
||||
name
|
||||
link:slug
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
Reference in New Issue
Block a user