1
0
Files
Bridges/DonCarneBridge.php
2025-11-25 20:09:28 +01:00

119 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
class DonCarneBridge extends BridgeAbstract
{
const MAINTAINER = 'Akamaru';
const NAME = 'Don Carne Neuheiten';
const URI = 'https://doncarne.de/';
const CACHE_TIMEOUT = 7200; // 2 hours
const DESCRIPTION = 'Zeigt die neuesten Produkte von Don Carne';
public function getIcon()
{
return 'https://www.google.com/s2/favicons?domain=doncarne.de&sz=32';
}
public function collectData()
{
// Build API URL with payload
$payload = json_encode([
'clerk-content-id' => 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 .= '<div style="text-align: center;">';
$content .= '<img src="' . htmlspecialchars($imageUrl) . '" alt="' . htmlspecialchars($item['title']) . '" style="max-width: 400px;">';
$content .= '</div><br>';
}
// Add discount badge if available
if ($discount) {
$content .= '<p><strong style="color: #e74c3c; font-size: 1.2em;">' . htmlspecialchars($discount) . '</strong></p>';
}
// Add price information
$content .= '<div style="font-size: 1.1em;">';
if ($price) {
$content .= '<strong>Preis: ' . number_format($price, 2, ',', '.') . ' €</strong>';
}
if ($listPrice && $listPrice > $price) {
$content .= ' <span style="text-decoration: line-through; color: #999;">(vorher: ' . number_format($listPrice, 2, ',', '.') . ' €)</span>';
}
$content .= '</div>';
// Add unit information
if ($baseUnit) {
$content .= '<p>Inhalt: ' . htmlspecialchars($baseUnit) . '</p>';
}
$item['content'] = $content;
$this->items[] = $item;
}
}
}