mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 03:31:23 +00:00
Moved product, all products (paths)
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
import { GetSiteCollectionsQuery } from '../schema'
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
|
||||
|
||||
const getAllCollections = async (options?: {
|
||||
variables?: any
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}) => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch<GetSiteCollectionsQuery>(
|
||||
getAllCollectionsQuery,
|
||||
{ variables }
|
||||
)
|
||||
|
||||
const categories = data.collections.edges.map(
|
||||
({ node: { id: entityId, title: name, handle } }) => ({
|
||||
entityId,
|
||||
name,
|
||||
path: `/${handle}`,
|
||||
})
|
||||
)
|
||||
|
||||
return {
|
||||
categories,
|
||||
}
|
||||
}
|
||||
|
||||
export default getAllCollections
|
@@ -1,41 +0,0 @@
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import { ProductEdge } from '../schema'
|
||||
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
|
||||
|
||||
type ProductPath = {
|
||||
path: string
|
||||
}
|
||||
|
||||
export type ProductPathNode = {
|
||||
node: ProductPath
|
||||
}
|
||||
|
||||
type ReturnType = {
|
||||
products: ProductPathNode[]
|
||||
}
|
||||
|
||||
const getAllProductPaths = async (options?: {
|
||||
variables?: any
|
||||
config?: ShopifyConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 100, sortKey: 'BEST_SELLING' } } =
|
||||
options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllProductsPathsQuery, {
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
products: data.products?.edges?.map(
|
||||
({ node: { handle } }: ProductEdge) => ({
|
||||
node: {
|
||||
path: `/${handle}`,
|
||||
},
|
||||
})
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
export default getAllProductPaths
|
@@ -1,34 +0,0 @@
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import { GetAllProductsQuery, Product as ShopifyProduct } from '../schema'
|
||||
import { getAllProductsQuery } from '../utils/queries'
|
||||
import { normalizeProduct } from '../utils/normalize'
|
||||
import { Product } from '../types/product'
|
||||
|
||||
type Variables = {
|
||||
first?: number
|
||||
field?: string
|
||||
}
|
||||
|
||||
const getAllProducts = async (options: {
|
||||
variables?: Variables
|
||||
config?: ShopifyConfig
|
||||
preview?: boolean
|
||||
}): Promise<{
|
||||
products: Product[]
|
||||
}> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch<GetAllProductsQuery>(
|
||||
getAllProductsQuery,
|
||||
{ variables }
|
||||
)
|
||||
|
||||
return {
|
||||
products: data.products.edges.map(({ node }) =>
|
||||
normalizeProduct(node as ShopifyProduct)
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
export default getAllProducts
|
@@ -1,33 +0,0 @@
|
||||
import { GetProductBySlugQuery, Product as ShopifyProduct } from '../schema'
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import { normalizeProduct, getProductQuery } from '../utils'
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
type Variables = {
|
||||
slug: string
|
||||
}
|
||||
|
||||
const getProduct = async (options: {
|
||||
variables: Variables
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}): Promise<{
|
||||
product?: Product
|
||||
}> => {
|
||||
let { config, variables } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const {
|
||||
data: { productByHandle },
|
||||
} = await config.fetch<GetProductBySlugQuery>(getProductQuery, {
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
...(productByHandle && {
|
||||
product: normalizeProduct(productByHandle as ShopifyProduct),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
export default getProduct
|
Reference in New Issue
Block a user