require_once __DIR__ . '/lib/db.php'; require_once __DIR__ . '/lib/translations.php'; require_once __DIR__ . '/lib/meta_capi.php'; $db = getDb(); $id = isset($_GET['id']) ? trim($_GET['id']) : ''; if (!$id) { header('Location: /index.php'); exit; } $stmt = $db->prepare("SELECT * FROM products WHERE id = ?"); $stmt->execute([$id]); $product = $stmt->fetch(); if (!$product) { header('Location: /index.php'); exit; } $title = getLocale() === 'fr' ? $product['title_fr'] : $product['title_en']; $priceVal = (float)$product['markup_price']; // Generate ViewContent event ID $viewContentEventId = 'vc_' . uniqid() . '_' . rand(10000, 99999); // Execute CAPI ViewContent event sendMetaCapiEvent('ViewContent', $viewContentEventId, [ 'content_name' => $title, 'content_ids' => [$id], 'content_type' => 'product', 'value' => $priceVal, 'currency' => 'CAD' ]); require_once __DIR__ . '/lib/header.php'; $images = explode(',', $product['image_urls']); $mainImage = $images[0]; $description = getLocale() === 'fr' ? $product['description_fr'] : $product['description_en']; $specs = json_decode($product['specs'], true) ?: []; $reviews = json_decode($product['reviews'], true) ?: []; $price = number_format($product['markup_price'], 2); $variants = isset($product['variants']) ? (json_decode($product['variants'], true) ?: []) : []; // Extract unique variant attributes (e.g. Size, Color) $attributeGroups = []; foreach ($variants as $v) { if (!empty($v['attrs'])) { foreach ($v['attrs'] as $name => $val) { if (!isset($attributeGroups[$name])) { $attributeGroups[$name] = []; } if (!in_array($val, $attributeGroups[$name])) { $attributeGroups[$name][] = $val; } } } } ?>