Search by

zdenekgebauer / zbozi-cz-feed

zdenekgebauer

Create product XML feed for Zbozi.cz

Package info

github.com/zdenekgebauer/zbozi-cz-feed

pkg:composer/zdenekgebauer/zbozi-cz-feed

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-12-02 16:25 UTC

This package is auto-updated.

Last update: 2026-12-02 16:28:04 UTC


README

Create the product XML feed for Zboží.cz by the specification
https://napoveda.sklik.cz/reklamy/xml-feed/specifikace/

Requirements

  • PHP 8.4 or newer
  • ext-json, ext-mbstring and ext-xmlwriter

No runtime dependencies beyond that.

Installation

composer require zdenekgebauer/zbozi-cz-feed

Usage

use ZdenekGebauer\ZboziCzFeed\Condition;
use ZdenekGebauer\ZboziCzFeed\Delivery;
use ZdenekGebauer\ZboziCzFeed\DeliveryDate;
use ZdenekGebauer\ZboziCzFeed\DeliveryId;
use ZdenekGebauer\ZboziCzFeed\ExtraMessage;
use ZdenekGebauer\ZboziCzFeed\Feed;
use ZdenekGebauer\ZboziCzFeed\Item;
use ZdenekGebauer\ZboziCzFeed\Param;
use ZdenekGebauer\ZboziCzFeed\SalesVoucher;

$feed = new Feed();
// truncates the file; items are appended to it in batches, so the whole feed never sits in memory
$feed->open('/path/to/zbozi.xml');

// required values
$item = new Item(
    itemId: 'SKU-123',
    productName: 'Samsung Galaxy S25 128 GB černý',
    description: 'Telefon s displejem 6,2"',
    url: 'https://example.org/samsung-galaxy-s25',
    priceVat: 19990.0,
    deliveryDate: DeliveryDate::inStock(),
    imgUrl: 'https://example.org/img/s25.jpg',
);

// optional values
$item->product = 'Samsung Galaxy S25';
$item->addImgUrlAlternative('https://example.org/img/s25-back.jpg');
$item->priceBeforeDiscount = 21990.0;
$item->addDelivery(new Delivery(DeliveryId::PPL, 99.0, 129.0));
$item->addDelivery(new Delivery(DeliveryId::ZASILKOVNA, 79.0));
$item->addCategoryText('Elektronika | Mobilní telefony');
$item->ean = '8806095000000';
$item->productNo = 'SM-S931B';
$item->manufacturer = 'Samsung';
$item->addParam(new Param('Barva', 'černá'));
$item->addParam(new Param('Hmotnost', '162', 'g'));
$item->itemGroupId = 'galaxy-s25';
$item->condition = Condition::NEW;
$item->warranty = 24;
$item->visibility = true;
$item->customLabel0 = 'novinka';
$item->addExtraMessage(ExtraMessage::FREE_GIFT, 'pouzdro');
$item->addExtraMessage(ExtraMessage::FREE_RETURN);
$item->addSalesVoucher(
    new SalesVoucher('SLEVA10', 17990.0, new DateTimeImmutable('2026-12-01'), new DateTimeImmutable('2026-12-31')),
);

$feed->add($item);
// ...add more items

$feed->close();

Delivery date

Method DELIVERY_DATE Meaning
DeliveryDate::inStock() 0 in stock, ships immediately
DeliveryDate::days(5) 5 ships within the given number of days
DeliveryDate::onDate($date) 2026-12-24 pre-order, available on the date
DeliveryDate::unknown() -1 availability unknown

Categories

Categories::parse() reads the category list published at https://www.zbozi.cz/static/categories.json (download it first) and yields the ID and full path of every leaf category, the value expected in CATEGORYTEXT:

use ZdenekGebauer\ZboziCzFeed\Categories;

foreach (new Categories()->parse('/path/to/categories.json') as $id => $categoryText) {
    // 1234 => 'Elektronika | Mobilní telefony'
}

Errors

Feed::add() validates the item before it writes anything and throws InvalidArgumentException when

  • itemId, productName, description, url or imgUrl is empty
  • priceVat is not greater than zero or priceBeforeDiscount is negative, or either is not finite
  • url, imgUrl or an alternative image URL does not start with http:// or https://, or contains whitespace, control or non-ASCII characters (zbozi.cz rejects such URLs; percent-encode each path segment, e.g. with rawurlencode())

Further InvalidArgumentExceptions:

Thrown by When
Delivery::__construct() a price is negative or not finite
SalesVoucher::__construct() the price is negative or not finite
DeliveryDate::days() the number of days is negative
Item::addCategoryText() more than 10 categories
Item::addImgUrlAlternative() more than 20 alternative images

Feed::add() and Feed::close() throw LogicException when open() was not called. Categories::parse() throws RuntimeException when the file is missing or is not a JSON list.

Output notes

  • Values over the length limits of the specification are truncated silently, by characters: PRODUCT 64, PRODUCTNAME 255, CATEGORYTEXT 500, ITEMGROUP_ID 36, CUSTOM_LABEL_0 and CUSTOM_LABEL_1 250, CUSTOM_LABEL_3 25, the text of an extra message 160, voucher CODE 24 and TEXT 128
  • HTML tags are stripped from DESCRIPTION
  • Free text (product name, description, parameters, labels, messages) is written as CDATA
  • Adding a second delivery with the same DeliveryId replaces the first one
  • An extra message text is written only for messages that have a text element: CUSTOM, FREE_ACCESSORIES, FREE_GIFT and VOUCHER
  • WARRANTY is written only when positive (999 = lifetime)

Known Issues

  • Values are not checked against the specification beyond the rules above — e.g. the EAN format, the length of ITEM_ID or the number of parameters
  • Only UTF-8 output

License

MIT, see LICENSE