sokil/php-merchant-product-feed

Facebook 和 Google 产品信息的构建者

0.1.0 2021-01-30 21:50 UTC

This package is auto-updated.

Last update: 2024-08-29 05:31:26 UTC


README

Facebook 和 Google 产品信息的构建者

Test Latest Stable Version Coverage Status Total Downloads Daily Downloads

Facebook

有用链接

Google

有用链接

用法

<?php

// 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;
}