PHP code example of inteve / feed-generator
1. Go to this page and download the library: Download inteve/feed-generator 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/ */
inteve / feed-generator example snippets php
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'));
php
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'));
php
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'));
php
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'));
php
$output = new Inteve\FeedGenerator\Outputs\FileOutput('/path/to/destination/feed.xml');
$feed->generate($output);
php
$output = new Inteve\FeedGenerator\Outputs\DirectOutput;
$feed->generate($output);
php
$output = new Inteve\FeedGenerator\Outputs\MemoryOutput;
$feed->generate($output);
echo $output->getOutput();
php
$response = new FeedGenerator\Responses\NetteDownloadResponse($feed, 'filename');
$presenter->sendResponse($response);
php
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);
}
}