'use client' import { useEffect, useState } from 'react' import Link from 'next/link' import Image from 'next/image' import { ShoppingBag } from 'lucide-react' import { useMedusaCart } from '@/hooks/useMedusaCart' const CURRENCY_SYMBOLS: Record = { zar: 'R', usd: '$', eur: '€', gbp: '£', kes: 'KSh', ngn: '₦', ghs: '₵' } const formatPrice = (amount: number, code?: string) => { const sym = CURRENCY_SYMBOLS[(code ?? '').toLowerCase()] ?? (code?.toUpperCase() ?? '') return `${sym}${(amount / 100).toFixed(2)}` } interface Variant { id: string; prices: Array<{ amount: number; currency_code: string }> } interface Product { id: string; title: string; thumbnail: string | null; variants: Variant[]; collection?: { id: string } } export default function YouMayAlsoLike({ currentProductId, collectionId }: { currentProductId: string; collectionId?: string }) { const [products, setProducts] = useState([]) const { addToCart } = useMedusaCart() useEffect(() => { const params = new URLSearchParams({ limit: '8' }) if (collectionId) params.set('collection_id[]', collectionId) fetch(`/api/medusa/store/products?${params}`) .then(r => r.ok ? r.json() : null) .then(data => { if (!data?.products) return setProducts(data.products.filter((p: Product) => p.id !== currentProductId).slice(0, 4)) }) .catch(() => {}) }, [currentProductId, collectionId]) if (products.length === 0) return null return (

You May Also Like

{products.map(product => { const variant = product.variants?.[0] const price = variant?.prices?.[0] return (
{product.thumbnail ? ( {product.title ) : (
)}

{product.title}

{price && (

{formatPrice(price.amount, price.currency_code)}

)}
) })}
) }