diff --git a/lib/constants.ts b/lib/constants.ts index 56bc6cd12..d41f7cfc4 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -1,3 +1,5 @@ +import { Collection, Page } from 'lib/shopify/types'; + export type SortFilterItem = { title: string; slug: string | null; @@ -29,3 +31,31 @@ export const TAGS = { export const HIDDEN_PRODUCT_TAG = 'nextjs-frontend-hidden'; export const DEFAULT_OPTION = 'Default Title'; export const SHOPIFY_GRAPHQL_API_ENDPOINT = '/api/2023-01/graphql.json'; + +export const PAGES: Page[] = []; + +const CURRENT_DATE = new Date().toISOString(); +export const COLLECTIONS: Collection[] = [ + { + handle: '', + title: 'All', + description: 'All products', + seo: { + title: 'All', + description: 'All products' + }, + path: '/search', + updatedAt: CURRENT_DATE + }, + { + handle: 'shirts', + title: 'Shirts', + description: 'Shirts', + seo: { + title: 'Shirts', + description: 'Shirts' + }, + path: '/search/shirts', + updatedAt: CURRENT_DATE + } +]; diff --git a/lib/shopify/index.ts b/lib/shopify/index.ts index 4ab6802e5..331faf8ec 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -1,4 +1,4 @@ -import { SHOPIFY_GRAPHQL_API_ENDPOINT, TAGS } from 'lib/constants'; +import { COLLECTIONS, SHOPIFY_GRAPHQL_API_ENDPOINT, TAGS } from 'lib/constants'; import { find, findByID } from 'lib/shopify/payload'; import { Media, Option, Product, Tag } from 'lib/shopify/payload-types'; import { isShopifyError } from 'lib/type-guards'; @@ -13,8 +13,7 @@ import { removeFromCartMutation } from './mutations/cart'; import { getCartQuery } from './queries/cart'; -import { getCollectionQuery, getCollectionsQuery } from './queries/collection'; -import { getPageQuery, getPagesQuery } from './queries/page'; +import { getPageQuery } from './queries/page'; import { Cart, Collection, @@ -30,11 +29,8 @@ import { ShopifyCart, ShopifyCartOperation, ShopifyCollection, - ShopifyCollectionOperation, - ShopifyCollectionsOperation, ShopifyCreateCartOperation, ShopifyPageOperation, - ShopifyPagesOperation, ShopifyRemoveFromCartOperation, ShopifyUpdateCartOperation } from './types'; @@ -218,15 +214,7 @@ export async function getCart(cartId: string): Promise { } export async function getCollection(handle: string): Promise { - const res = await shopifyFetch({ - query: getCollectionQuery, - tags: [TAGS.collections], - variables: { - handle - } - }); - - return reshapeCollection(res.body.data.collection); + return COLLECTIONS.find((collection) => collection.handle === handle); } const reshapeImage = (media: Media): Image => { @@ -321,54 +309,33 @@ export async function getCollectionProducts({ reverse?: boolean; sortKey?: string; }): Promise { + console.log(sortKey); + const products = await find('products', {}); return products.docs.map(reshapeProduct); } export async function getCollections(): Promise { - const res = await shopifyFetch({ - query: getCollectionsQuery, - tags: [TAGS.collections] - }); - const shopifyCollections = removeEdgesAndNodes(res.body?.data?.collections); - const collections = [ - { - handle: '', - title: 'All', - description: 'All products', - seo: { - title: 'All', - description: 'All products' - }, - path: '/search', - updatedAt: new Date().toISOString() - }, - // Filter out the `hidden` collections. - // Collections that start with `hidden-*` need to be hidden on the search page. - ...reshapeCollections(shopifyCollections).filter( - (collection) => !collection.handle.startsWith('hidden') - ) - ]; - - return collections; + return COLLECTIONS; } export async function getMenu(handle: string): Promise { - return []; - // const res = await shopifyFetch({ - // query: getMenuQuery, - // tags: [TAGS.collections], - // variables: { - // handle - // } - // }); - - // return ( - // res.body?.data?.menu?.items.map((item: { title: string; url: string }) => ({ - // title: item.title, - // path: item.url.replace(domain, '').replace('/collections', '/search').replace('/pages', '') - // })) || [] - // ); + switch (handle) { + case 'next-js-frontend-footer-menu': + return [ + { title: 'About Medusa', path: 'https://medusajs.com/' }, + { title: 'Medusa Docs', path: 'https://docs.medusajs.com/' }, + { title: 'Medusa Blog', path: 'https://medusajs.com/blog' } + ]; + case 'next-js-frontend-header-menu': + return [ + { title: 'All', path: '/search' }, + { title: 'Shirts', path: '/search/shirts' }, + { title: 'Stickers', path: '/search/stickers' } + ]; + default: + return []; + } } export async function getPage(handle: string): Promise { @@ -382,12 +349,7 @@ export async function getPage(handle: string): Promise { } export async function getPages(): Promise { - const res = await shopifyFetch({ - query: getPagesQuery, - cache: 'no-store' - }); - - return removeEdgesAndNodes(res.body.data.pages); + return []; } export async function getProduct(handle: string): Promise {