From 3e2502c545e8067ee03ad255f3e36af70d91ca9b Mon Sep 17 00:00:00 2001 From: Vula Builder Date: Tue, 28 Jul 2026 12:39:42 +0000 Subject: [PATCH] Deploy --- src/components/shop/YouMayAlsoLike.tsx | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/components/shop/YouMayAlsoLike.tsx diff --git a/src/components/shop/YouMayAlsoLike.tsx b/src/components/shop/YouMayAlsoLike.tsx new file mode 100644 index 0000000..33b4ad2 --- /dev/null +++ b/src/components/shop/YouMayAlsoLike.tsx @@ -0,0 +1,78 @@ +'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)} +

+ )} + +
+
+ ) + })} +
+
+ ) +}