diff --git a/app/product/[handle]/page.tsx b/app/product/[handle]/page.tsx index e2280675d..71a65198d 100644 --- a/app/product/[handle]/page.tsx +++ b/app/product/[handle]/page.tsx @@ -7,7 +7,7 @@ import { Gallery } from 'components/product/gallery'; import { ProductProvider } from 'components/product/product-context'; import { ProductDescription } from 'components/product/product-description'; import { HIDDEN_PRODUCT_TAG } from 'lib/constants'; -import { getProduct, getProductRecommendations } from 'lib/shopify'; +import { getProduct, getProductRecommendations } from 'lib/fourthwall'; import { Image } from 'lib/shopify/types'; import Link from 'next/link'; import { Suspense } from 'react'; diff --git a/lib/fourthwall/index.ts b/lib/fourthwall/index.ts index 82793462f..ec52cd539 100644 --- a/lib/fourthwall/index.ts +++ b/lib/fourthwall/index.ts @@ -1,6 +1,6 @@ import { Cart, Menu, Product } from "lib/shopify/types"; -import { reshapeCart, reshapeProducts } from "./reshape"; -import { FourthwallCart } from "./types"; +import { reshapeCart, reshapeProduct, reshapeProducts } from "./reshape"; +import { FourthwallCart, FourthwallProduct } from "./types"; /** * Helpers @@ -72,7 +72,7 @@ export async function getCollectionProducts({ reverse?: boolean; sortKey?: string; }): Promise { - const res = await fourthwallGet<{results: any[]}>(`${process.env.FW_URL}/api/public/v1.0/collections/${collection}/products?secret=${process.env.FW_SECRET}`, { + const res = await fourthwallGet<{results: FourthwallProduct[]}>(`${process.env.FW_URL}/api/public/v1.0/collections/${collection}/products?secret=${process.env.FW_SECRET}`, { headers: { 'X-ShopId': process.env.FW_SHOPID || '' } @@ -87,6 +87,27 @@ export async function getCollectionProducts({ return reshapeProducts(res.body.results); } +/** + * Product operations + */ +export async function getProduct(handle: string): Promise { + // TODO: replace with real URL + const res = await fourthwallGet<{results: FourthwallProduct[]}>(`${process.env.FW_URL}/api/public/v1.0/collections/${process.env.FW_COLLECTION}/products?secret=${process.env.FW_SECRET}`, { + headers: { + 'X-ShopId': process.env.FW_SHOPID || '' + } + }); + + return res.body.results.filter((product) => { + return product.slug === handle + }).map((p: any) => reshapeProduct(p))[0]; +} + +export async function getProductRecommendations(productId: string): Promise { + // TODO: replace with real URL + return []; +} + /** * Cart operations */ diff --git a/lib/fourthwall/reshape.ts b/lib/fourthwall/reshape.ts index 2d9e99215..d50b0e6e1 100644 --- a/lib/fourthwall/reshape.ts +++ b/lib/fourthwall/reshape.ts @@ -38,7 +38,7 @@ export const reshapeProducts = (products: FourthwallProduct[]) => { return reshapedProducts; }; -const reshapeProduct = (product: FourthwallProduct): Product | undefined => { +export const reshapeProduct = (product: FourthwallProduct): Product | undefined => { if (!product) { return undefined; } @@ -117,7 +117,8 @@ const reshapeCartItem = (item: FourthwallCartItem): CartItem => { // TODO: Stubbed out selectedOptions: [], product: { - id: 'TT', + // TODO: need this product info in model + id: 'TT', handle: 'TT', title: 'TT', featuredImage: { diff --git a/lib/shopify/index.ts b/lib/shopify/index.ts index 52fb8029e..c17ec0ad9 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -10,8 +10,6 @@ import { } from './queries/collection'; import { getPageQuery, getPagesQuery } from './queries/page'; import { - getProductQuery, - getProductRecommendationsQuery, getProductsQuery } from './queries/product'; import { @@ -28,8 +26,6 @@ import { ShopifyPageOperation, ShopifyPagesOperation, ShopifyProduct, - ShopifyProductOperation, - ShopifyProductRecommendationsOperation, ShopifyProductsOperation } from './types'; @@ -243,30 +239,6 @@ export async function getPages(): Promise { return removeEdgesAndNodes(res.body.data.pages); } -export async function getProduct(handle: string): Promise { - const res = await shopifyFetch({ - query: getProductQuery, - tags: [TAGS.products], - variables: { - handle - } - }); - - return reshapeProduct(res.body.data.product, false); -} - -export async function getProductRecommendations(productId: string): Promise { - const res = await shopifyFetch({ - query: getProductRecommendationsQuery, - tags: [TAGS.products], - variables: { - productId - } - }); - - return reshapeProducts(res.body.data.productRecommendations); -} - export async function getProducts({ query, reverse,