[ 'name' => 'Number of products', 'type' => 'number', 'defaultValue' => 20, 'required' => false, ], ], ]; public function getIcon() { return 'https://www.google.com/s2/favicons?domain=funstock.eu&sz=32'; } public function collectData() { $limit = $this->getInput('limit') ?: 20; $apiUrl = 'https://funstock.eu/collections/evercade/products.json?sort_by=created-descending&limit=' . $limit; $json = getContents($apiUrl); if (!$json) { returnServerError('Could not fetch data from Funstock'); } $data = json_decode($json, true); if (!$data || !isset($data['products'])) { returnServerError('Invalid JSON response from Funstock'); } foreach ($data['products'] as $product) { $item = []; $item['title'] = $product['title']; $item['uri'] = 'https://funstock.eu/products/' . $product['handle']; $item['uid'] = (string) $product['id']; // Timestamp (creation date) if (isset($product['created_at'])) { $item['timestamp'] = strtotime($product['created_at']); } // Author/Vendor if (isset($product['vendor']) && !empty($product['vendor'])) { $item['author'] = $product['vendor']; } // Categories/Tags if (isset($product['tags']) && is_array($product['tags'])) { $item['categories'] = $product['tags']; } // Price from first variant $price = ''; if (isset($product['variants'][0]['price'])) { $price = $product['variants'][0]['price'] . ' EUR'; } // Product type $productType = $product['product_type'] ?? ''; // Build content $content = ''; // Product image if (isset($product['images'][0]['src'])) { $imageUrl = $product['images'][0]['src']; $content .= '
' . htmlspecialchars($product['title']) . '

'; $item['enclosures'][] = $imageUrl; } // Price and type if ($price || $productType) { $content .= '

'; if ($price) { $content .= 'Price: ' . htmlspecialchars($price); } if ($price && $productType) { $content .= ' | '; } if ($productType) { $content .= 'Type: ' . htmlspecialchars($productType); } $content .= '

'; } // Description (clean HTML) if (isset($product['body_html']) && !empty($product['body_html'])) { $description = $product['body_html']; // Remove empty paragraphs $description = preg_replace('/

\s*( |\s)*<\/p>/', '', $description); $content .= '


' . $description; } $item['content'] = $content; $this->items[] = $item; } } }