3, 'no_design' => true, 'template' => 'startseite-new-products', 'key' => 'wrXs8M5FbwXUkEJ48gd9trLmivRd09Gq', 'visitor' => 'auto' ]); $apiUrl = 'https://api.clerk.io/v2/recommendations/new?payload=' . urlencode($payload); // Fetch API data $jsonString = getContents($apiUrl); if (!$jsonString) { return; } $data = json_decode($jsonString, true); if (!$data || !isset($data['product_data']) || $data['status'] !== 'ok') { return; } foreach ($data['product_data'] as $product) { $item = []; // Get product ID if (!isset($product['id'])) { continue; } $item['uid'] = $product['id']; // Get product title and URL $item['title'] = $product['name'] ?? 'Unbekanntes Produkt'; $item['uri'] = $product['url'] ?? self::URI; $item['author'] = 'Don Carne'; // Get product image (with fallbacks) $imageUrl = null; if (isset($product['clerk_cover_thumb'])) { $imageUrl = $product['clerk_cover_thumb']; } elseif (isset($product['image'])) { $imageUrl = $product['image']; } elseif (isset($product['images']) && is_array($product['images']) && count($product['images']) > 0) { $imageUrl = $product['images'][0]; } if ($imageUrl) { $item['enclosures'][] = $imageUrl; } // Get discount badge $discount = null; if (isset($product['CustomBadge']) && is_array($product['CustomBadge']) && count($product['CustomBadge']) > 0) { $discount = $product['CustomBadge'][0]; $item['categories'][] = $discount; } // Get price information $price = $product['price'] ?? null; $listPrice = $product['list_price'] ?? null; // Get unit information $baseUnit = $product['base_unit'] ?? ''; // Build content HTML $content = ''; // Add product image if ($imageUrl) { $content .= '
' . htmlspecialchars($discount) . '
'; } // Add price information $content .= 'Inhalt: ' . htmlspecialchars($baseUnit) . '
'; } $item['content'] = $content; $this->items[] = $item; } } }