commerce/lib/constants.ts
2025-03-26 16:02:22 -04:00

59 lines
1.2 KiB
TypeScript

export type SortFilterItem = {
title: string
slug: string | null
sortKey: 'RELEVANCE' | 'BEST_SELLING' | 'CREATED_AT' | 'PRICE'
reverse: boolean
}
export const defaultSort: SortFilterItem = {
title: 'Relevance',
slug: null,
sortKey: 'RELEVANCE',
reverse: false,
}
export const sorting: SortFilterItem[] = [
defaultSort,
{
title: 'Trending',
slug: 'trending-desc',
sortKey: 'BEST_SELLING',
reverse: false,
}, // asc
{
title: 'Latest arrivals',
slug: 'latest-desc',
sortKey: 'CREATED_AT',
reverse: true,
},
{
title: 'Price: Low to high',
slug: 'price-asc',
sortKey: 'PRICE',
reverse: false,
}, // asc
{
title: 'Price: High to low',
slug: 'price-desc',
sortKey: 'PRICE',
reverse: true,
},
]
export const TAGS = {
collections: 'collections',
products: 'products',
cart: 'cart',
}
export const HIDDEN_PRODUCT_TAG = 'nextjs-frontend-hidden'
export const DEFAULT_OPTION = 'Default Title'
export function getShopifyGraphqlEndpoint() {
const storeDomain = process.env.SHOPIFY_STORE_DOMAIN
if (!storeDomain) {
throw new Error('SHOPIFY_STORE_DOMAIN environment variable is not set')
}
return `https://${storeDomain}/api/2023-01/graphql.json`
}