// src/app/produit/[slug]/page.tsx import { Metadata } from 'next'; import { notFound } from 'next/navigation'; import { WooCommerceService, formatPrice, isOnSale, getDiscountPercentage } from '@/lib/woocommerce'; import ProductImageGallery from '@/components/product/ProductImageGallery'; import ProductInfo from '@/components/product/ProductInfo'; import RelatedProducts from '@/components/product/RelatedProducts'; import ProductTabs from '@/components/product/ProductTabs'; import Breadcrumb from '@/components/ui/breadcrumb'; interface ProductPageProps { params: { slug: string; }; } export async function generateMetadata({ params }: ProductPageProps): Promise { const response = await WooCommerceService.getProductBySlug(params.slug); if (!response.success || !response.data) { return { title: 'Produit non trouvé', }; } const product = response.data; const discountPercentage = getDiscountPercentage(product); return { title: `${product.name} - MELHFA`, description: product.short_description || product.description, openGraph: { title: product.name, description: product.short_description || product.description, images: product.images.map(img => ({ url: img.src, width: 800, height: 1200, alt: img.alt || product.name, })), type: 'product', }, twitter: { card: 'summary_large_image', title: product.name, description: product.short_description || product.description, images: [product.images[0]?.src || ''], }, alternates: { canonical: `/produit/${product.slug}`, }, other: { 'product:price:amount': product.price, 'product:price:currency': 'MRU', 'product:availability': product.stock_status === 'instock' ? 'in stock' : 'out of stock', 'product:condition': 'new', ...(isOnSale(product) && { 'product:sale_price:amount': product.sale_price, 'product:sale_price:currency': 'MRU', }), }, }; } export default async function ProductPage({ params }: ProductPageProps): Promise { // Récupérer le produit const response = await WooCommerceService.getProductBySlug(params.slug); if (!response.success || !response.data) { notFound(); } const product = response.data; // Récupérer les produits liés const relatedProductsResponse = await WooCommerceService.getProducts({ per_page: 4, exclude: [product.id], category: product.categories[0]?.slug, }); const relatedProducts = relatedProductsResponse.data || []; // Breadcrumb items const breadcrumbItems = [ { label: 'Accueil', href: '/' }, { label: 'Boutique', href: '/boutique' }, ...(product.categories.length > 0 ? [{ label: product.categories[0].name, href: `/boutique?category=${product.categories[0].slug}` }] : []), { label: product.name, href: `/produit/${product.slug}` }, ]; return (
{/* Breadcrumb */}
{/* Product Details */}
{/* Image Gallery */}
{/* Product Info */}
{/* Product Tabs */}
{/* Related Products */} {relatedProducts.length > 0 && (
)} {/* Structured Data for SEO */}