Use new endpoints

This commit is contained in:
goncy 2021-08-11 10:43:50 -03:00
parent d2b45da873
commit 9aa4871418
7 changed files with 46 additions and 31 deletions

View File

@ -1,6 +1,6 @@
{
"features": {
"cart": false,
"cart": true,
"search": false,
"wishlist": false,
"customerAuth": false,

View File

@ -22,7 +22,7 @@ export default function getAllProductPathsOperation({
// Get all products
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
'GET',
'/products'
'/me/products'
).then((response) => response.Items)
return {

View File

@ -23,7 +23,7 @@ export default function getAllProductsOperation({
// Get all products
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
'GET',
'/products'
'/me/products'
).then((response) => response.Items)
return {

View File

@ -24,7 +24,7 @@ export default function getProductOperation({
// Get a single product
const rawProduct: RawProduct = await fetch<RawProduct>(
'GET',
`/products/${variables?.slug}`
`/me/products/${variables?.slug}`
)
return {

View File

@ -1,6 +1,8 @@
import { OperationContext } from '@commerce/api/operations'
import { Category } from '@commerce/types/site'
import { OrdercloudConfig } from '../index'
import type { OperationContext } from '@commerce/api/operations'
import type { Category, GetSiteInfoOperation } from '@commerce/types/site'
import { RawCategory } from '@framework/types/category'
import type { OrdercloudConfig, Provider } from '../index'
export type GetSiteInfoResult<
T extends { categories: any[]; brands: any[] } = {
@ -9,34 +11,36 @@ export type GetSiteInfoResult<
}
> = T
export default function getSiteInfoOperation({}: OperationContext<any>) {
function getSiteInfo({
query,
variables,
config: cfg,
export default function getSiteInfoOperation({
commerce,
}: OperationContext<Provider>) {
async function getSiteInfo<T extends GetSiteInfoOperation>({
config,
}: {
query?: string
variables?: any
config?: Partial<OrdercloudConfig>
preview?: boolean
} = {}): Promise<GetSiteInfoResult> {
return Promise.resolve({
categories: [
{
id: 'new-arrivals',
name: 'New Arrivals',
slug: 'new-arrivals',
path: '/new-arrivals',
},
{
id: 'featured',
name: 'Featured',
slug: 'featured',
path: '/featured',
},
],
} = {}): Promise<T['data']> {
// Get fetch from the config
const { fetch } = commerce.getConfig(config)
// Get a single product
const rawCategories: RawCategory[] = await fetch<{ Items: RawCategory[] }>(
'GET',
`/me/categories`
).then((response) => response.Items)
return {
// Normalize product to commerce schema
categories: rawCategories.map((category) => ({
id: category.ID,
name: category.Name,
slug: category.ID,
path: `/${category.ID}`,
})),
brands: [],
})
}
}
return getSiteInfo

View File

@ -2,8 +2,9 @@
"provider": "ordercloud",
"features": {
"wishlist": false,
"cart": false,
"cart": true,
"search": false,
"customerAuth": false
"customerAuth": false,
"customCheckout": false
}
}

View 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
}