Compare color
Renk karşılaştırma özelliği yakında eklenecektir.
queryOne( "SELECT p.*, c.name as category_name, c.slug as category_slug, b.name as brand_name, b.slug as brand_slug FROM products p LEFT JOIN categories c ON p.category_id = c.id LEFT JOIN brands b ON p.brand_id = b.id WHERE p.slug = ? AND p.status = 'active'", [$product_slug] ); } elseif ($product_id > 0) { $product = $db->queryOne( "SELECT p.*, c.name as category_name, c.slug as category_slug, b.name as brand_name, b.slug as brand_slug FROM products p LEFT JOIN categories c ON p.category_id = c.id LEFT JOIN brands b ON p.brand_id = b.id WHERE p.id = ? AND p.status = 'active'", [$product_id] ); } if (!$product) { // Ürün bulunamadı, 404 sayfasına yönlendir header("HTTP/1.0 404 Not Found"); include __DIR__ . '/404.php'; exit; } // Görüntülenme sayısını artır $db->execute( "UPDATE products SET view_count = view_count + 1 WHERE id = ?", [$product['id']] ); // Görsel path'ini düzelt ve URL oluştur function fixImagePath($image) { if (empty($image) || $image === null || $image === 'null' || $image === '') { return null; } // Eğer zaten tam URL ise, olduğu gibi döndür if (strpos($image, 'http://') === 0 || strpos($image, 'https://') === 0) { return $image; } // Path'i temizle - başındaki ve sonundaki slash'leri kaldır $image = trim($image, '/'); // Eğer zaten uploads/ ile başlıyorsa, uploads/ kısmını kaldır if (strpos($image, 'uploads/') === 0) { $image = substr($image, 8); // 'uploads/' uzunluğu 8 } // Eğer products/ ile başlıyorsa, olduğu gibi döndür if (strpos($image, 'products/') === 0) { return $image; } // Sadece dosya adı ise products/ ekle return 'products/' . $image; } // Görsel URL'ini oluştur (zaten fixImagePath ile işlenmiş path için) function getImageUrl($image) { if (empty($image)) { return null; } // Eğer zaten tam URL ise, olduğu gibi döndür if (strpos($image, 'http://') === 0 || strpos($image, 'https://') === 0) { return $image; } // Path zaten fixImagePath ile işlenmiş durumda (products/ ile başlıyor) // Direkt upload_url ile tam URL oluştur return upload_url($image); } // Galeri görsellerini çek $gallery_images = []; if (!empty($product['gallery_images'])) { // JSON string'i decode et $gallery_images_raw = json_decode($product['gallery_images'], true); // Eğer JSON decode başarısız olduysa, direkt string olarak dene if ($gallery_images_raw === null && json_last_error() !== JSON_ERROR_NONE) { // JSON değilse, tek bir string olabilir $gallery_images_raw = [$product['gallery_images']]; } // Debug: JSON decode başarısız olduysa log if ($gallery_images_raw === null) { error_log('Product gallery_images JSON decode failed for product ID: ' . $product['id']); error_log('Raw gallery_images: ' . substr($product['gallery_images'], 0, 200)); } if (is_array($gallery_images_raw) && !empty($gallery_images_raw)) { foreach ($gallery_images_raw as $img) { // Boş değerleri filtrele if (!empty($img) && (is_string($img) || is_numeric($img))) { $img_str = is_string($img) ? trim($img) : (string)$img; if ($img_str !== '' && $img_str !== 'null' && $img_str !== null && $img_str !== false) { $fixed_path = fixImagePath($img_str); if ($fixed_path && !in_array($fixed_path, $gallery_images, true)) { $gallery_images[] = $fixed_path; } } } } } } // Ana görseli galeriye ekle (eğer galeri boşsa veya featured image galeride yoksa) if (!empty($product['featured_image'])) { $fixed_featured = fixImagePath($product['featured_image']); if ($fixed_featured) { // Eğer zaten galeri görsellerinde yoksa veya galeri boşsa başa ekle if (empty($gallery_images) || !in_array($fixed_featured, $gallery_images, true)) { array_unshift($gallery_images, $fixed_featured); } } } // Eğer hiç görsel yoksa placeholder göster (sadece featured_image de yoksa) // Featured image varsa onu kullan, yoksa placeholder göster if (empty($gallery_images)) { // Placeholder için products/ prefix'i ekle $gallery_images = ['placeholder.jpg']; } // Ürün varyantlarını çek $product_variants = $db->query( "SELECT * FROM product_variants WHERE product_id = ? ORDER BY id ASC", [$product['id']] ) ?: []; // Ürün özelliklerini çek (renk, beden vb.) - Varyantlardan özellikleri çıkar $product_attributes = []; if (!empty($product_variants)) { $attribute_ids = []; foreach ($product_variants as $variant) { if (!empty($variant['attribute_data'])) { $attr_data = json_decode($variant['attribute_data'], true); if (is_array($attr_data)) { foreach ($attr_data as $attr) { if (isset($attr['attribute_id']) && !in_array($attr['attribute_id'], $attribute_ids)) { $attribute_ids[] = $attr['attribute_id']; } } } } } if (!empty($attribute_ids)) { $placeholders = implode(',', array_fill(0, count($attribute_ids), '?')); $product_attributes = $db->query( "SELECT * FROM product_attributes WHERE id IN ($placeholders) ORDER BY sort_order", $attribute_ids ) ?: []; // Her özellik için değerleri çek foreach ($product_attributes as &$attr) { $attr['values'] = $db->query( "SELECT * FROM product_attribute_values WHERE attribute_id = ? ORDER BY sort_order", [$attr['id']] ) ?: []; } } } // İlgili ürünleri çek (aynı kategoriden) if ($product['category_id']) { $related_products = $db->query( "SELECT p.*, c.name as category_name, c.slug as category_slug FROM products p LEFT JOIN categories c ON p.category_id = c.id WHERE p.category_id = ? AND p.id != ? AND p.status = 'active' ORDER BY p.featured DESC, p.created_at DESC LIMIT 8", [$product['category_id'], $product['id']] ) ?: []; } // Ürün yorumlarını çek $reviews = $db->query( "SELECT pr.*, u.first_name, u.last_name, u.email FROM product_reviews pr LEFT JOIN users u ON pr.user_id = u.id WHERE pr.product_id = ? AND pr.status = 'approved' ORDER BY pr.created_at DESC LIMIT 50", [$product['id']] ) ?: []; // Ortalama puanı hesapla if (!empty($reviews)) { $total_rating = 0; foreach ($reviews as $review) { $total_rating += $review['rating']; } $average_rating = round($total_rating / count($reviews), 1); } } catch (Exception $e) { error_log('Product detail error: ' . $e->getMessage()); header("HTTP/1.0 404 Not Found"); include __DIR__ . '/404.php'; exit; } // Sepet ve wishlist sayıları $cart_count = 0; $wishlist_count = 0; try { if ($is_logged_in) { $userId = getUserId(); $cart_count = $db->queryValue( "SELECT SUM(quantity) FROM cart WHERE user_id = ?", [$userId] ) ?: 0; $wishlist_count = $db->queryValue( "SELECT COUNT(*) FROM wishlist WHERE user_id = ?", [$userId] ) ?: 0; // Bu ürün wishlist'te mi kontrol et $is_in_wishlist = $db->queryValue( "SELECT COUNT(*) FROM wishlist WHERE user_id = ? AND product_id = ?", [$userId, $product['id']] ) > 0; } else { $sessionId = session_id(); $cart_count = $db->queryValue( "SELECT SUM(quantity) FROM cart WHERE session_id = ?", [$sessionId] ) ?: 0; $is_in_wishlist = false; } } catch (Exception $e) { error_log('Cart/Wishlist count error: ' . $e->getMessage()); $cart_count = 0; $wishlist_count = 0; $is_in_wishlist = false; } // Sayfa başlığı $page_title = htmlspecialchars($product['name']) . ' - ' . SITE_NAME; $page_description = !empty($product['meta_description']) ? htmlspecialchars($product['meta_description']) : htmlspecialchars($product['short_description'] ?? ''); $page_keywords = $product['meta_keywords'] ?? ''; // Ürün detay sayfası için özel CSS ve JS dosyaları $extra_css = [ 'css/drift-basic.min.css', 'css/photoswipe.css', 'css/image-compare-viewer.min.css' ]; // image-compare-viewer.js modül hatası veriyor, şimdilik kaldırıyoruz // photoswipe.min.js dosyası yok, magnific-popup kullanılıyor $extra_js = [ 'js/drift.min.js' ]; // Head layout'unu dahil et include LAYOUTS_PATH . '/head.php'; ?>
Estimate delivery times: 12-26 days (International), 3-6 days (United States).
Return within 30 days of purchase. Duties & taxes are non-refundable.
Guarantee Safe
Checkout