1. Go to this page and download the library: Download baraja-core/heureka-feed library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
baraja-core / heureka-feed example snippets
declare(strict_types=1);
namespace App\Services;
use Baraja\Heureka\ProductLoader;
use Baraja\Heureka\HeurekaProduct;
use Baraja\Heureka\CategoryManager;
use Baraja\Heureka\Delivery;
final class MyProductLoader implements ProductLoader
{
public function __construct(
private CategoryManager $categoryManager,
private ProductRepository $productRepository,
) {
}
/**
* @return HeurekaProduct[]
*/
public function getProducts(): array
{
$products = [];
foreach ($this->productRepository->findAllActive() as $product) {
$heurekaProduct = new HeurekaProduct(
itemId: (string) $product->getId(),
product: $product->getName(),
productName: $product->getFullName(),
url: 'https://example.com/product/' . $product->getSlug(),
priceVat: $product->getPrice(),
category: $this->categoryManager->getCategory($product->getHeurekaCategoryId()),
manufacturer: $product->getManufacturer(),
);
$heurekaProduct->setDescription($product->getDescription());
$heurekaProduct->setImgUrl($product->getMainImageUrl());
$heurekaProduct->setDeliveryDate($product->getDeliveryDays());
if ($product->getEan() !== null) {
$heurekaProduct->setEan($product->getEan());
}
$heurekaProduct->addDelivery(new Delivery(Delivery::PPL, 99.0));
$heurekaProduct->addDelivery(new Delivery(Delivery::ZASILKOVNA, 59.0, 79.0));
$products[] = $heurekaProduct;
}
return $products;
}
}
use Baraja\Heureka\Delivery;
// Basic delivery
$delivery = new Delivery(Delivery::PPL, 99.0);
// Delivery with COD (cash on delivery) price
$delivery = new Delivery(Delivery::ZASILKOVNA, 59.0, 79.0);
$product->addDelivery($delivery);
use Baraja\Heureka\CategoryManager;
class MyService
{
public function __construct(
private CategoryManager $categoryManager,
) {
}
public function example(): void
{
// Get a specific category by ID
$category = $this->categoryManager->getCategory(123);
// Get all categories as flat array
$allCategories = $this->categoryManager->getCategories();
// Get categories formatted for selectbox (id => name)
$selectableCategories = $this->categoryManager->getSelectableCategories();
// Get categories as tree-structured selectbox (with indentation)
$selectboxTree = $this->categoryManager->getCategoriesSelectbox();
}
}
$category->getId(); // int - Category ID
$category->getName(); // string - Category name
$category->getParent(); // ?Category - Parent category
$category->getParentId(); // ?int - Parent category ID
$category->getCategoryText(); // string - Full path (e.g., "Heureka.cz | Electronics | Phones")
$category->getParentsPath(); // array - [id => name] of all parents
use Baraja\Heureka\DescriptionRenderer;
final class HtmlStripperDescriptionRenderer implements DescriptionRenderer
{
public function render(string $haystack): string
{
return strip_tags($haystack);
}
}
use Baraja\Heureka\FeedRenderer;
use Baraja\Heureka\CategoryManager;
use Nette\Http\Response;
use Nette\Caching\Storages\MemoryStorage;
// Create dependencies
$storage = new MemoryStorage();
$response = new Response();
$categoryManager = new CategoryManager($storage);
// Create renderer
$feedRenderer = new FeedRenderer($response);
$feedRenderer->setProductLoader(new MyProductLoader($categoryManager));
// Render feed
$feedRenderer->render();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.