PHP code example of sokil / php-merchant-product-feed

1. Go to this page and download the library: Download sokil/php-merchant-product-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/ */

    

sokil / php-merchant-product-feed example snippets




// build set of products
$product = new Product(
    'sku',
    'title',
    'description',
    new Availability(Availability::IN_STOCK),
    new Condition(Condition::NEW),
    new Price('42.42', 'UAH'),
    new Url('https://example.com/item'),
    new Url('https://example.com/item.png'),
    'SomeBrand'
);

// build feed
$feed = new Feed([$product]);

// create formatter, devince product normaliser for martketing platform and define encoder to some formats
$formatter = new Formatter(
    [new FacebookProductNormaliser()],
    [new FacebookFeedCsvEncoder()]
);

// formatted feed is generator which yields parts of feed
$generator = $formatter->format($feed, 'facebook', 'csv');

// send feed to output
header('Content-type: text/csv');

foreach ($generator as $streamChunk) {
    echo $streamChunk;
}