diff --git a/app/api/cart/route.ts b/app/api/cart/route.ts index 15f5fb09f..788b6b781 100644 --- a/app/api/cart/route.ts +++ b/app/api/cart/route.ts @@ -1,7 +1,7 @@ import { cookies } from 'next/headers'; import { NextRequest, NextResponse } from 'next/server'; -import { addToCart, removeFromCart, updateCart } from 'lib/shopify'; +import { addToCart, removeFromCart, updateCart } from 'lib/medusa'; import { isShopifyError } from 'lib/type-guards'; function formatErrorMessage(err: Error): string { @@ -10,13 +10,13 @@ function formatErrorMessage(err: Error): string { export async function POST(req: NextRequest): Promise { const cartId = cookies().get('cartId')?.value; - const { merchandiseId } = await req.json(); + const { variantId } = await req.json(); - if (!cartId?.length || !merchandiseId?.length) { + if (!cartId?.length || !variantId?.length) { return NextResponse.json({ error: 'Missing cartId or variantId' }, { status: 400 }); } try { - await addToCart(cartId, [{ merchandiseId, quantity: 1 }]); + await addToCart(cartId, [{ variantId, quantity: 1 }]); return NextResponse.json({ status: 204 }); } catch (e) { if (isShopifyError(e)) { diff --git a/app/product/[handle]/page.tsx b/app/product/[handle]/page.tsx index 1b1eb4821..194b22c42 100644 --- a/app/product/[handle]/page.tsx +++ b/app/product/[handle]/page.tsx @@ -10,8 +10,8 @@ import { Gallery } from 'components/product/gallery'; import { VariantSelector } from 'components/product/variant-selector'; import Prose from 'components/prose'; import { HIDDEN_PRODUCT_TAG } from 'lib/constants'; -import { getProduct } from 'lib/shopify'; -import { Image } from 'lib/shopify/types'; +import { getProduct } from 'lib/medusa'; +import { Image } from 'lib/medusa/types'; export const runtime = 'edge'; diff --git a/app/search/[collection]/page.tsx b/app/search/[collection]/page.tsx index 0e1782b7d..60f73f280 100644 --- a/app/search/[collection]/page.tsx +++ b/app/search/[collection]/page.tsx @@ -1,4 +1,4 @@ -import { getCollection, getCollectionProducts } from 'lib/shopify'; +import { getCollection, getCollectionProducts } from 'lib/medusa'; import { Metadata } from 'next'; import { notFound } from 'next/navigation'; diff --git a/app/search/page.tsx b/app/search/page.tsx index 354a2022f..3b6809269 100644 --- a/app/search/page.tsx +++ b/app/search/page.tsx @@ -1,7 +1,7 @@ import Grid from 'components/grid'; import ProductGridItems from 'components/layout/product-grid-items'; import { defaultSort, sorting } from 'lib/constants'; -import { getProducts } from 'lib/shopify'; +import { getProducts } from 'lib/medusa'; export const runtime = 'edge'; diff --git a/app/sitemap.ts b/app/sitemap.ts index f4745dbc9..f2789dba2 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,4 +1,4 @@ -import { getCollections, getProducts } from 'lib/shopify'; +import { getCollections, getProducts } from 'lib/medusa'; import { MetadataRoute } from 'next'; const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL diff --git a/components/carousel.tsx b/components/carousel.tsx index 30b6a4733..a1ddcfda7 100644 --- a/components/carousel.tsx +++ b/components/carousel.tsx @@ -1,4 +1,4 @@ -import { getCollectionProducts } from 'lib/shopify'; +import { getCollectionProducts } from 'lib/medusa'; import Image from 'next/image'; import Link from 'next/link'; diff --git a/components/cart/button.tsx b/components/cart/button.tsx index aed87ee7a..5a3f538f7 100644 --- a/components/cart/button.tsx +++ b/components/cart/button.tsx @@ -6,7 +6,7 @@ import { useCookies } from 'react-cookie'; import CartIcon from 'components/icons/cart'; import CartModal from './modal'; -import type { Cart } from 'lib/shopify/types'; +import type { Cart } from 'lib/medusa/types'; export default function CartButton({ cart, diff --git a/components/cart/delete-item-button.tsx b/components/cart/delete-item-button.tsx index 789a87754..25f5a3b1a 100644 --- a/components/cart/delete-item-button.tsx +++ b/components/cart/delete-item-button.tsx @@ -4,7 +4,7 @@ import { useRouter } from 'next/navigation'; import { startTransition, useState } from 'react'; import clsx from 'clsx'; -import type { CartItem } from 'lib/shopify/types'; +import type { CartItem } from 'lib/medusa/types'; export default function DeleteItemButton({ item }: { item: CartItem }) { const router = useRouter(); diff --git a/components/cart/edit-item-quantity-button.tsx b/components/cart/edit-item-quantity-button.tsx index 2249bd1aa..6b8bb72fe 100644 --- a/components/cart/edit-item-quantity-button.tsx +++ b/components/cart/edit-item-quantity-button.tsx @@ -4,7 +4,7 @@ import { startTransition, useState } from 'react'; import clsx from 'clsx'; import MinusIcon from 'components/icons/minus'; import PlusIcon from 'components/icons/plus'; -import type { CartItem } from 'lib/shopify/types'; +import type { CartItem } from 'lib/medusa/types'; import LoadingDots from '../loading-dots'; export default function EditItemQuantityButton({ diff --git a/components/cart/index.tsx b/components/cart/index.tsx index 0e3ffcdc1..8d9adca32 100644 --- a/components/cart/index.tsx +++ b/components/cart/index.tsx @@ -1,4 +1,4 @@ -import { createCart, getCart } from 'lib/shopify'; +import { createCart, getCart } from 'lib/medusa'; import { cookies } from 'next/headers'; import CartButton from './button'; diff --git a/components/cart/modal.tsx b/components/cart/modal.tsx index 4220cfe94..0af119350 100644 --- a/components/cart/modal.tsx +++ b/components/cart/modal.tsx @@ -7,7 +7,7 @@ import CloseIcon from 'components/icons/close'; import ShoppingBagIcon from 'components/icons/shopping-bag'; import Price from 'components/price'; import { DEFAULT_OPTION } from 'lib/constants'; -import type { Cart } from 'lib/shopify/types'; +import type { Cart } from 'lib/medusa/types'; import { createUrl } from 'lib/utils'; import DeleteItemButton from './delete-item-button'; import EditItemQuantityButton from './edit-item-quantity-button'; @@ -70,13 +70,13 @@ export default function CartModal({ - {cart.lines.length === 0 ? ( + {cart.lines?.length === 0 ? (

Your cart is empty.

) : null} - {cart.lines.length !== 0 ? ( + {cart.lines?.length !== 0 ? (
- }> - {/* @ts-expect-error Server Component */} - - + {/* }> */} + {/* @ts-expect-error Server Component */} + {/* */} + {/* */}
); diff --git a/components/layout/navbar/mobile-menu.tsx b/components/layout/navbar/mobile-menu.tsx index c960d5218..fffff9dc7 100644 --- a/components/layout/navbar/mobile-menu.tsx +++ b/components/layout/navbar/mobile-menu.tsx @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react'; import CloseIcon from 'components/icons/close'; import MenuIcon from 'components/icons/menu'; -import { Menu } from 'lib/shopify/types'; +import { Menu } from 'lib/medusa/types'; import Search from './search'; export default function MobileMenu({ menu }: { menu: Menu[] }) { diff --git a/components/layout/product-grid-items.tsx b/components/layout/product-grid-items.tsx index 0c0e907ed..380a7111a 100644 --- a/components/layout/product-grid-items.tsx +++ b/components/layout/product-grid-items.tsx @@ -1,6 +1,6 @@ import Grid from 'components/grid'; import { GridTileImage } from 'components/grid/tile'; -import { Product } from 'lib/shopify/types'; +import { Product } from 'lib/medusa/types'; import Link from 'next/link'; export default function ProductGridItems({ products }: { products: Product[] }) { diff --git a/components/layout/search/collections.tsx b/components/layout/search/collections.tsx index e4abb8d4a..5f3f8920e 100644 --- a/components/layout/search/collections.tsx +++ b/components/layout/search/collections.tsx @@ -1,7 +1,7 @@ import clsx from 'clsx'; import { Suspense } from 'react'; -import { getCollections } from 'lib/shopify'; +import { getCollections } from 'lib/medusa'; import FilterList from './filter'; async function CollectionList() { diff --git a/components/product/add-to-cart.tsx b/components/product/add-to-cart.tsx index 9da11bafa..8142ba4cc 100644 --- a/components/product/add-to-cart.tsx +++ b/components/product/add-to-cart.tsx @@ -5,7 +5,7 @@ import { useRouter, useSearchParams } from 'next/navigation'; import { useEffect, useState, useTransition } from 'react'; import LoadingDots from 'components/loading-dots'; -import { ProductVariant } from 'lib/shopify/types'; +import { ProductVariant } from 'lib/medusa/types'; export function AddToCart({ variants, diff --git a/components/product/variant-selector.tsx b/components/product/variant-selector.tsx index 520818516..2f95d06af 100644 --- a/components/product/variant-selector.tsx +++ b/components/product/variant-selector.tsx @@ -1,7 +1,7 @@ 'use client'; import clsx from 'clsx'; -import { ProductOption, ProductVariant } from 'lib/shopify/types'; +import { ProductOption, ProductVariant } from 'lib/medusa/types'; import { createUrl } from 'lib/utils'; import Link from 'next/link'; import { usePathname, useRouter, useSearchParams } from 'next/navigation'; diff --git a/lib/shopify/index.ts b/lib/shopify/index.ts index 11f426649..75f281c7c 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -1,5 +1,6 @@ import { isShopifyError } from 'lib/type-guards'; -import { Cart, Collection, Product } from './types'; +import { ProductCollection } from '../medusa/types'; +import { Cart, Product } from './types'; // const endpoint = `${process.env.MEDUSA_BACKEND_API!}`; const endpoint = `http://localhost:9000/store`; @@ -49,18 +50,19 @@ export default async function medusaRequest( export async function createCart(): Promise { const res = await medusaRequest('POST', '/carts', {}); + console.log('Cart created!'); + console.log(res); return res.body.cart; } export async function addToCart( cartId: string, - lines: { merchandiseId: string; quantity: number }[] + lineItems: { variantId: string; quantity: number }[] ): Promise { - console.log(lines); + console.log(lineItems); // TODO: transform lines into Medusa line items const res = await medusaRequest('POST', `/carts/${cartId}/line-items`, { - variant_id: 'something', - quantity: 1 + lineItems }); return res.body.data.cart; @@ -93,8 +95,9 @@ export async function getCart(cartId: string): Promise { return res.body.cart; } -export async function getCollection(handle: string): Promise { +export async function getCollection(handle: string): Promise { const res = await medusaRequest('get', `/collections?handle[]=${handle}&limit=1`); + console.log({ collection: res.body.collection }); return res.body.collection; } @@ -103,11 +106,11 @@ export async function getCollectionProducts(handle: string): Promise if (!res.body?.collection?.products) { return []; } - + console.log({ 'collection products': res.body.collection.products }); return res.body.collection.products; } -export async function getCollections(): Promise { +export async function getCollections(): Promise { const collections = [ { handle: '', @@ -122,7 +125,7 @@ export async function getCollections(): Promise { } ]; - return collections; + return []; } export async function getProduct(handle: string): Promise {