Installation
composer require bitbag/sylius-feed-plugin
Update config/bundles.php with the required bundles (ensure SetonoSyliusFeedPlugin is registered before SyliusGridBundle).
Database Migrations Run:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Feed Creation Use the admin UI to create a new feed via:
Google Merchant Center).feed_url, authentication).Generate a Test Feed
php bin/console sylius_feed:generate <feed-id>
Verify output in the configured storage (e.g., public/feeds/).
Create a Feed:
Google Merchant Center as the feed type.merchant_id (your GMC merchant ID).country (target country, e.g., US).feed_url (e.g., https://example.com/feeds/google.xml).daily at 2 AM.Map Product Fields:
name, price, sku) to GMC’s required fields (e.g., title, price, gtin).Product name → title
Product price → price
Product SKU → gtin
Test Locally:
php bin/console sylius_feed:generate <feed-id>
Deploy to GMC:
feed_url in your Google Merchant Center account.PriceRunner, Ceneo, Google Shopping).use Setono\SyliusFeedPlugin\Entity\FeedInterface;
$feed = $feedRepository->createNew();
$feed->setType('google_merchant_center');
$feed->setFeedUrl('https://example.com/feeds/google.xml');
$feed->setSchedule('0 2 * * *'); // Cron syntax
$feed->setEnabled(true);
$feedManager->save($feed);
product.name, product.price) to feed-specific fields (e.g., title, price).
product.name + product.variant.sku).$mapping = $feed->getFieldMapping();
$mapping->addField('title', 'product.name');
$mapping->addField('price', 'product.price', [
'transformer' => 'currency', // Convert to float
]);
$mapping->addField('image_link', 'product.media.first.url');
php bin/console sylius_feed:generate <feed-id>
* * * * * /usr/bin/php /path/to/your/project/bin/console sylius_feed:generate <feed-id>
sylius_feed.generate events to trigger feeds dynamically (e.g., after a product update):
use Setono\SyliusFeedPlugin\Event\FeedGenerateEvent;
$eventDispatcher->addListener(FeedGenerateEvent::NAME, function (FeedGenerateEvent $event) {
if ($event->getFeed()->getType() === 'google_merchant_center') {
// Custom logic (e.g., notify GMC of changes)
}
});
$filter = $feed->getFilter();
$filter->addCondition('product.category', 'IN', ['electronics', 'clothing']);
$filter->addCondition('product.onHand', '>', 0);
public/feeds/. Configure via config/packages/setono_sylius_feed_plugin.yaml:
setono_sylius_feed_plugin:
storage:
type: local
directory: '%kernel.project_dir%/public/feeds'
setono_sylius_feed_plugin:
storage:
type: flysystem
service_id: my_flysystem_service
Facebook Catalogs):
namespace App\FeedType;
use Setono\SyliusFeedPlugin\FeedType\FeedTypeInterface;
use Setono\SyliusFeedPlugin\FeedType\FeedTypeTrait;
class FacebookCatalogFeedType implements FeedTypeInterface
{
use FeedTypeTrait;
public function getName(): string
{
return 'facebook_catalog';
}
public function getConfigurationFormType(): string
{
return FacebookCatalogConfigurationType::class;
}
public function getFieldMappingFormType(): string
{
return FacebookCatalogFieldMappingType::class;
}
}
services:
app.feed_type.facebook_catalog:
class: App\FeedType\FacebookCatalogFeedType
tags:
- { name: sylius_feed.feed_type }
namespace App\Transformer;
use Setono\SyliusFeedPlugin\Transformer\TransformerInterface;
class PriceTransformer implements TransformerInterface
{
public function transform($value, array $options): string
{
return number_format((float) $value, 2, '.', '');
}
}
config/packages/setono_sylius_feed_plugin.yaml:
setono_sylius_feed_plugin:
transformers:
price: App\Transformer\PriceTransformer
use Setono\SyliusFeedPlugin\Event\FeedGenerateEvent;
$eventDispatcher->addListener(FeedGenerateEvent::NAME, function (FeedGenerateEvent $event) {
if ($event->isSuccess()) {
$feed = $event->getFeed();
$client = new \GuzzleHttp\Client();
$client->post('https://your-cdn.com/invalidate', [
'json' => ['path' => $feed->getFeedUrl()]
]);
}
});
sylius_feed:generate command with --dry-run to preview output:
php bin/console sylius_feed:generate <feed-id> --dry-run
use Symfony\Component\Validator\Validator\ValidatorInterface;
$validator = $this->container->get(ValidatorInterface::class);
$feedContent = file_get_contents($feed->getFeedUrl());
$violations = $validator->validate($feedContent, [
new \Setono\SyliusFeedPlugin\Validator\FeedSchemaConstraint()
]);
How can I help you explore Laravel packages today?