mirror of
https://github.com/vercel/commerce.git
synced 2025-07-03 19:51:22 +00:00
Use new endpoints
This commit is contained in:
parent
d2b45da873
commit
9aa4871418
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"features": {
|
"features": {
|
||||||
"cart": false,
|
"cart": true,
|
||||||
"search": false,
|
"search": false,
|
||||||
"wishlist": false,
|
"wishlist": false,
|
||||||
"customerAuth": false,
|
"customerAuth": false,
|
||||||
|
@ -22,7 +22,7 @@ export default function getAllProductPathsOperation({
|
|||||||
// Get all products
|
// Get all products
|
||||||
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
|
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
|
||||||
'GET',
|
'GET',
|
||||||
'/products'
|
'/me/products'
|
||||||
).then((response) => response.Items)
|
).then((response) => response.Items)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -23,7 +23,7 @@ export default function getAllProductsOperation({
|
|||||||
// Get all products
|
// Get all products
|
||||||
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
|
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
|
||||||
'GET',
|
'GET',
|
||||||
'/products'
|
'/me/products'
|
||||||
).then((response) => response.Items)
|
).then((response) => response.Items)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -24,7 +24,7 @@ export default function getProductOperation({
|
|||||||
// Get a single product
|
// Get a single product
|
||||||
const rawProduct: RawProduct = await fetch<RawProduct>(
|
const rawProduct: RawProduct = await fetch<RawProduct>(
|
||||||
'GET',
|
'GET',
|
||||||
`/products/${variables?.slug}`
|
`/me/products/${variables?.slug}`
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { OperationContext } from '@commerce/api/operations'
|
import type { OperationContext } from '@commerce/api/operations'
|
||||||
import { Category } from '@commerce/types/site'
|
import type { Category, GetSiteInfoOperation } from '@commerce/types/site'
|
||||||
import { OrdercloudConfig } from '../index'
|
import { RawCategory } from '@framework/types/category'
|
||||||
|
|
||||||
|
import type { OrdercloudConfig, Provider } from '../index'
|
||||||
|
|
||||||
export type GetSiteInfoResult<
|
export type GetSiteInfoResult<
|
||||||
T extends { categories: any[]; brands: any[] } = {
|
T extends { categories: any[]; brands: any[] } = {
|
||||||
@ -9,34 +11,36 @@ export type GetSiteInfoResult<
|
|||||||
}
|
}
|
||||||
> = T
|
> = T
|
||||||
|
|
||||||
export default function getSiteInfoOperation({}: OperationContext<any>) {
|
export default function getSiteInfoOperation({
|
||||||
function getSiteInfo({
|
commerce,
|
||||||
query,
|
}: OperationContext<Provider>) {
|
||||||
variables,
|
async function getSiteInfo<T extends GetSiteInfoOperation>({
|
||||||
config: cfg,
|
config,
|
||||||
}: {
|
}: {
|
||||||
query?: string
|
query?: string
|
||||||
variables?: any
|
variables?: any
|
||||||
config?: Partial<OrdercloudConfig>
|
config?: Partial<OrdercloudConfig>
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
} = {}): Promise<GetSiteInfoResult> {
|
} = {}): Promise<T['data']> {
|
||||||
return Promise.resolve({
|
// Get fetch from the config
|
||||||
categories: [
|
const { fetch } = commerce.getConfig(config)
|
||||||
{
|
|
||||||
id: 'new-arrivals',
|
// Get a single product
|
||||||
name: 'New Arrivals',
|
const rawCategories: RawCategory[] = await fetch<{ Items: RawCategory[] }>(
|
||||||
slug: 'new-arrivals',
|
'GET',
|
||||||
path: '/new-arrivals',
|
`/me/categories`
|
||||||
},
|
).then((response) => response.Items)
|
||||||
{
|
|
||||||
id: 'featured',
|
return {
|
||||||
name: 'Featured',
|
// Normalize product to commerce schema
|
||||||
slug: 'featured',
|
categories: rawCategories.map((category) => ({
|
||||||
path: '/featured',
|
id: category.ID,
|
||||||
},
|
name: category.Name,
|
||||||
],
|
slug: category.ID,
|
||||||
|
path: `/${category.ID}`,
|
||||||
|
})),
|
||||||
brands: [],
|
brands: [],
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return getSiteInfo
|
return getSiteInfo
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
"provider": "ordercloud",
|
"provider": "ordercloud",
|
||||||
"features": {
|
"features": {
|
||||||
"wishlist": false,
|
"wishlist": false,
|
||||||
"cart": false,
|
"cart": true,
|
||||||
"search": false,
|
"search": false,
|
||||||
"customerAuth": false
|
"customerAuth": false,
|
||||||
|
"customCheckout": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
framework/ordercloud/types/category.ts
Normal file
10
framework/ordercloud/types/category.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export interface RawCategory {
|
||||||
|
ID: string
|
||||||
|
Name: string
|
||||||
|
Description: null | string
|
||||||
|
ListOrder: number
|
||||||
|
Active: boolean
|
||||||
|
ParentID: null
|
||||||
|
ChildCount: number
|
||||||
|
xp: null
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user