query($q)) { while ($row = $res->fetch_assoc()) { // normalize fields and defaults $row['id'] = isset($row['id']) ? (int)$row['id'] : 0; // prefer column name patterns: title/name if (empty($row['name']) && !empty($row['title'])) $row['name'] = $row['title']; if (empty($row['title']) && !empty($row['name'])) $row['title'] = $row['name']; // images: if stored as JSON array, decode; if single filename, make array; if URL, keep it $images = []; if (!empty($row['images'])) { // try JSON decode first $maybe = json_decode($row['images'], true); if (is_array($maybe)) { $images = $maybe; } else { // if comma-separated or single if (strpos($row['images'], ',') !== false) { $images = array_map('trim', explode(',', $row['images'])); } else { $images = [ $row['images'] ]; } } } elseif (!empty($row['image'])) { $images = [ $row['image'] ]; } // normalize image URLs: if value looks like URL (http/https) keep, else prefix uploads/ $images = array_values(array_filter(array_map(function($src){ $src = trim((string)$src); if ($src === '') return null; if (preg_match('#^https?://#i', $src)) return $src; // local file return 'uploads/' . ltrim($src, '/\\'); }, $images))); $row['images'] = $images; // features: try decode JSON or comma-split $features = []; if (!empty($row['features'])) { $maybe = json_decode($row['features'], true); if (is_array($maybe)) $features = $maybe; else { $features = array_map('trim', explode('|', str_replace(',', '|', $row['features']))); } } $row['features'] = $features; // other nice-to-have fields (fallbacks) $row['category'] = $row['category'] ?? ($row['cat'] ?? ''); $row['rating'] = $row['rating'] ?? '—'; $row['products'] = $row['products'] ?? ($row['product_count'] ?? '—'); $row['delivery'] = $row['delivery'] ?? ($row['ship_time'] ?? '—'); $row['description'] = $row['description'] ?? ($row['excerpt'] ?? ''); $row['fullDescription'] = $row['fullDescription'] ?? ($row['full_description'] ?? $row['description']); $shops[] = $row; } $res->free(); } else { // query error — but still show page error_log("shop.php query failed: " . $db->error); } // helper to pick first visible image for a shop (or empty string) function first_image(array $shop): string { if (!empty($shop['images']) && is_array($shop['images']) && count($shop['images'])>0) { return $shop['images'][0]; } return ''; } ?> فروشگاه های آنلاین افغانستان

فروشگاه های آنلاین افغانستان

بهترین پلتفرم‌های خریدوفروش آنلاین که در افغانستان فعالیت دارند

هیچ فروشگاهی یافت نشد — دیتابیس خالی است یا خطایی رخ داده است.