mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 12:11:22 +00:00
Icky 175 (#3)
* folder and env setup * codegen.json headers removed * icky-175-get-site-info * PR comments resolved * update category Id Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>
This commit is contained in:
parent
0e5c68ef58
commit
449d7fee72
11
framework/kibocommerce/api/fragments/category.ts
Normal file
11
framework/kibocommerce/api/fragments/category.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export const CategoryInfo = /* GraphQL */`
|
||||||
|
fragment categoryInfo on PrCategory {
|
||||||
|
categoryId
|
||||||
|
categoryCode
|
||||||
|
isDisplayed
|
||||||
|
content {
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
description
|
||||||
|
}
|
||||||
|
}`;
|
@ -1,6 +1,8 @@
|
|||||||
import { OperationContext } from '@commerce/api/operations'
|
import { OperationContext } from '@commerce/api/operations'
|
||||||
import { Category } from '@commerce/types/site'
|
import { Category } from '@commerce/types/site'
|
||||||
import { KiboCommerceConfig } from '../index'
|
import { KiboCommerceConfig } from '../index'
|
||||||
|
import {categoryTreeQuery} from '../queries/get-categories-tree-query'
|
||||||
|
import { normalizeCategory } from '../../lib/normalize'
|
||||||
|
|
||||||
export type GetSiteInfoResult<
|
export type GetSiteInfoResult<
|
||||||
T extends { categories: any[]; brands: any[] } = {
|
T extends { categories: any[]; brands: any[] } = {
|
||||||
@ -9,32 +11,22 @@ export type GetSiteInfoResult<
|
|||||||
}
|
}
|
||||||
> = T
|
> = T
|
||||||
|
|
||||||
export default function getSiteInfoOperation({}: OperationContext<any>) {
|
export default function getSiteInfoOperation({commerce}: OperationContext<any>) {
|
||||||
function getSiteInfo({
|
async function getSiteInfo({
|
||||||
query,
|
query= categoryTreeQuery,
|
||||||
variables,
|
variables,
|
||||||
config: cfg,
|
config,
|
||||||
}: {
|
}: {
|
||||||
query?: string
|
query?: string
|
||||||
variables?: any
|
variables?: any
|
||||||
config?: Partial<KiboCommerceConfig>
|
config?: Partial<KiboCommerceConfig>
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
} = {}): Promise<GetSiteInfoResult> {
|
} = {}): Promise<GetSiteInfoResult> {
|
||||||
|
const cfg = commerce.getConfig(config)
|
||||||
|
const { data } = await cfg.fetch(query);
|
||||||
|
const categories= data.categories.items.map(normalizeCategory);
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
categories: [
|
categories: categories ?? [],
|
||||||
{
|
|
||||||
id: 'new-arrivals',
|
|
||||||
name: 'New Arrivals',
|
|
||||||
slug: 'new-arrivals',
|
|
||||||
path: '/new-arrivals',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'featured',
|
|
||||||
name: 'Featured',
|
|
||||||
slug: 'featured',
|
|
||||||
path: '/featured',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
brands: [],
|
brands: [],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import { CategoryInfo } from '../fragments/category'
|
||||||
|
|
||||||
|
export const categoryTreeQuery = /* GraphQL */`
|
||||||
|
query GetCategoryTree {
|
||||||
|
categories: categoriesTree {
|
||||||
|
items {
|
||||||
|
...categoryInfo
|
||||||
|
childrenCategories {
|
||||||
|
...categoryInfo
|
||||||
|
childrenCategories {
|
||||||
|
...categoryInfo
|
||||||
|
childrenCategories {
|
||||||
|
...categoryInfo
|
||||||
|
childrenCategories {
|
||||||
|
...categoryInfo
|
||||||
|
childrenCategories {
|
||||||
|
...categoryInfo
|
||||||
|
childrenCategories {
|
||||||
|
...categoryInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
${CategoryInfo}`;
|
@ -5,10 +5,15 @@
|
|||||||
// import { definitions } from '../api/definitions/store-content'
|
// import { definitions } from '../api/definitions/store-content'
|
||||||
import update from './immutability'
|
import update from './immutability'
|
||||||
import getSlug from './get-slug'
|
import getSlug from './get-slug'
|
||||||
|
import {PrCategory} from '../schema'
|
||||||
|
|
||||||
function normalizeProductOption(productOption: any) {
|
function normalizeProductOption(productOption: any) {
|
||||||
const {
|
const {
|
||||||
node: { entityId, values: { edges = [] } = {}, ...rest },
|
node: {
|
||||||
|
entityId,
|
||||||
|
values: { edges = [] } = {},
|
||||||
|
...rest
|
||||||
|
},
|
||||||
} = productOption
|
} = productOption
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -127,11 +132,11 @@ function normalizeLineItem(item: any): any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeCategory(category: any): any {
|
export function normalizeCategory(category: PrCategory): any {
|
||||||
return {
|
return {
|
||||||
id: `${category.entityId}`,
|
id: category?.categoryCode,
|
||||||
name: category.name,
|
name: category?.content?.name,
|
||||||
slug: getSlug(category.path),
|
slug: category?.content?.slug,
|
||||||
path: category.path,
|
path: `/${category?.content?.slug}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14551
package-lock.json
generated
14551
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user