Componette

Componette

inteve

inteve / feed-generator v1.4.0

Feed Generator for Nette and more.

download-cloud-line composer require inteve/feed-generator

Feed Generator

Tests Status

Become a Patron! Buy me a coffee

Installation

Download a latest package or use Composer:

composer require inteve/feed-generator

Feed Generator requires PHP 5.6.0 or later.

Usage

Feeds

Google Merchant

use Inteve\FeedGenerator\Feeds\GoogleMerchant;

$feed = new GoogleMerchant\GoogleMerchantFeed;
$feed->setTitle('Products');
$feed->setWebsiteUrl('http://www.example.com/');
$feed->setUpdated(new DateTime('2017-01-01 00:00:00 UTC'));
$feed->setAuthor('Example.com');
$items = array();

foreach ($products as $product) {
	$item = new GoogleMerchant\GoogleMerchantItem;
	$item->setId($product->id)
		->setTitle($product->title)
		->setDescription($product->description)
		->setUrl('https://www.example.com/product/' . $product->url)
		->setImageUrl('https://www.example.com/images/product/' . $product->id)
		->setAvailability($product->qty > 0 ? $item::AVAILABILITY_IN_STOCK : $item::AVAILABILITY_OUT_OF_STOCK)
		->setPrice($product->price, 'USD');
	$items[] = $item;
}

$feed->setItems($items);
$feed->generate(new Inteve\FeedGenerator\Outputs\FileOutput(__DIR__ . '/feeds/google.xml'));

Glami.cz

use Inteve\FeedGenerator\Feeds\Glami;

$feed = new Glami\GlamiFeed;
$items = array();

foreach ($products as $product) {
	$items[] = Glami\GlamiItem::create()
		->setId($product->id)
		->setProductName($product->name)
		->setDescription($product->description)
		->setCategoryText($product->categoryName)
		->setUrl('http://www.example.com/product/' . $product->url)
		->setImageUrl('https://www.example.com/images/product/' . $product->id)
		->setPriceVat($product->price)
		->setDeliveryDate($product->qty > 0 ? 0 : 10) // number of days
		->addParameter('velikost', 'XS');
}

$feed->setItems($items);
$feed->generate(new Inteve\FeedGenerator\Outputs\FileOutput(__DIR__ . '/feeds/glami.xml'));

Heureka.cz

use Inteve\FeedGenerator\Feeds\Heureka;

$feed = new Heureka\HeurekaFeed;
$items = array();

foreach ($products as $product) {
	$items[] = Heureka\HeurekaItem::create()
		->setId($product->id)
		->setProductName($product->name)
		->setDescription($product->description)
		->setCategoryText($product->categoryName)
		->setUrl('http://www.example.com/product/' . $product->url)
		->setImageUrl('https://www.example.com/images/product/' . $product->id)
		->setPrice($product->price)
		->setDeliveryDate($product->qty > 0 ? 0 : 10); // number of days or DateTime
}

$feed->setItems($items);
$feed->generate(new Inteve\FeedGenerator\Outputs\FileOutput(__DIR__ . '/feeds/heureka.xml'));

Zbozi.cz

use Inteve\FeedGenerator\Feeds\Zbozi;

$feed = new Zbozi\ZboziFeed;
$items = array();

foreach ($products as $product) {
	$items[] = Zbozi\ZboziItem::create()
		->setId($product->id)
		->setProductName($product->name)
		->setDescription($product->description)
		->setUrl('http://www.example.com/product/' . $product->url)
		->setImageUrl('https://www.example.com/images/product/' . $product->id)
		->setPrice($product->price)
		->setDeliveryDate($product->qty > 0 ? 0 : 10); // number of days or DateTime
}

$feed->setItems($items);
$feed->generate(new Inteve\FeedGenerator\Outputs\FileOutput(__DIR__ . '/feeds/zbozi.xml'));

Outputs

FileOutput

Sends output to file.

$output = new Inteve\FeedGenerator\Outputs\FileOutput('/path/to/destination/feed.xml');
$feed->generate($output);

DirectOutput

Sends output to STDIN.

$output = new Inteve\FeedGenerator\Outputs\DirectOutput;
$feed->generate($output);

MemoryOutput

Saves output in memory.

$output = new Inteve\FeedGenerator\Outputs\MemoryOutput;
$feed->generate($output);
echo $output->getOutput();

Integrations

Requires package nette/application.

$response = new FeedGenerator\Responses\NetteDownloadResponse($feed, 'filename');
$presenter->sendResponse($response);

For example:

class FeedPresenter extends Nette\Application\UI\Presenter
{
	public function actionGoogle()
	{
		$feed = new FeedGenerator\Feeds\GoogleMerchant\GoogleMerchantFeed;
		// prepare feed & items

		$response = new FeedGenerator\Responses\NetteDownloadResponse($feed, 'google.xml');
		$this->sendResponse($response);
	}
}

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/

  • v1.4.0 Version v1.4.0

    • added GlamiFeed
    • added support for nette/utils ^3.0
    • Feeds - added posibility to skip item (item can be NULL)
    • added ItemsGroup
  • v1.3.0 Version v1.3.0

    • PostFeed - added support for metadata
  • v1.2.0 Version 1.2.0

    • dropped support for PHP 5.4 & 5.5
    • Heureka: added support for EAN (#1)
  • v1.1.0 Version 1.1.0

    • added Feeds\ZboziFeed
    • added Feeds\HeurekaFeed
  • v1.0.0 Version 1.0.0

    First public release.

bar-chart-fill

Statistics

download-cloud-fill
2172
star-fill
1
bug-fill
2
flashlight-fill
2.8y
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=5.6.0)
Componette Componette felix@nette.org