diff --git a/frontend/application/app/shop/[id]/page.tsx b/frontend/application/app/shop/[id]/page.tsx index 3a94e85..5909530 100644 --- a/frontend/application/app/shop/[id]/page.tsx +++ b/frontend/application/app/shop/[id]/page.tsx @@ -1,6 +1,78 @@ import ProductPage from "../../../components/ProductPage"; +import { productService } from "../../../lib/services/productService"; +import type { Metadata, ResolvingMetadata } from 'next'; + +export async function generateMetadata( + { params }: { params: Promise<{ id: string }> }, + parent: ResolvingMetadata +): Promise { + const resolvedParams = await params; + const product = await productService.getProductById(resolvedParams.id); + + if (!product) { + return { + title: 'محصول یافت نشد', + }; + } + + // Get raw data for custom fields if we added them (like metaTitle) + // Since we don't have local access to raw DB object without modifying productService, + // we can just use the mapped product fields for now. + const title = (product as any).metaTitle || product.name; + const description = (product as any).metaDescription || product.description; + const keywords = (product as any).keywords ? (product as any).keywords.split(',') : product.main_ingredients; + + return { + title, + description, + keywords, + openGraph: { + title, + description, + images: [product.image], + }, + alternates: { + canonical: (product as any).canonicalUrl || `/shop/${product.id}`, + } + }; +} export default async function ShopProductPage({ params }: { params: Promise<{ id: string }> }) { const resolvedParams = await params; - return ; + const product = await productService.getProductById(resolvedParams.id); + + if (!product) { + return ; + } + + const jsonLd = { + '@context': 'https://schema.org', + '@type': 'Product', + name: product.name, + image: product.image, + description: (product as any).metaDescription || product.description, + sku: product.artNo, + brand: { + '@type': 'Brand', + name: 'Canina' + }, + offers: { + '@type': 'Offer', + url: `https://canina-iran.com/shop/${product.id}`, + priceCurrency: 'IRR', + price: product.priceValue * 10, // Assuming priceValue is in Toman, converting to Rial + availability: 'https://schema.org/InStock', + itemCondition: 'https://schema.org/NewCondition' + } + }; + + return ( + <> +