Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sylius Feed Plugin Laravel Package

bitbag/sylius-feed-plugin

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require bitbag/sylius-feed-plugin
    

    Update config/bundles.php with the required bundles (ensure SetonoSyliusFeedPlugin is registered before SyliusGridBundle).

  2. Database Migrations Run:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. First Feed Creation Use the admin UI to create a new feed via:

    • Admin PanelFeedsCreate New Feed
    • Select a feed type (e.g., Google Merchant Center).
    • Configure settings (e.g., feed_url, authentication).
    • Define a schedule (manual, cron, or immediate).
  4. Generate a Test Feed

    php bin/console sylius_feed:generate <feed-id>
    

    Verify output in the configured storage (e.g., public/feeds/).


First Use Case: Google Merchant Center Feed

  1. Create a Feed:

    • Select Google Merchant Center as the feed type.
    • Configure:
      • merchant_id (your GMC merchant ID).
      • country (target country, e.g., US).
      • feed_url (e.g., https://example.com/feeds/google.xml).
    • Set schedule to daily at 2 AM.
  2. Map Product Fields:

    • Use the Field Mapping tab to link Sylius product attributes (e.g., name, price, sku) to GMC’s required fields (e.g., title, price, gtin).
    • Example mapping:
      Product name → title
      Product price → price
      Product SKU → gtin
      
  3. Test Locally:

    • Generate the feed manually:
      php bin/console sylius_feed:generate <feed-id>
      
    • Validate against Google’s feed rules.
  4. Deploy to GMC:

    • Submit the feed_url in your Google Merchant Center account.
    • Monitor for errors in the Feed Issues section of the admin panel.

Implementation Patterns

Core Workflows

1. Feed Creation & Configuration

  • Admin UI Workflow:
    1. Navigate to FeedsCreate.
    2. Select a feed type (e.g., PriceRunner, Ceneo, Google Shopping).
    3. Configure general settings (URL, authentication, schedule).
    4. Define field mappings (link Sylius entities to feed schema).
    5. Set filters (e.g., only active products, specific categories).
  • Programmatic Creation (for CLI or custom admin panels):
    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);
    

2. Field Mapping

  • UI-Based Mapping: Use the Field Mapping tab to drag-and-drop Sylius fields (e.g., product.name, product.price) to feed-specific fields (e.g., title, price).
    • Supports custom transformations (e.g., concatenate product.name + product.variant.sku).
  • Programmatic Mapping:
    $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');
    

3. Scheduling & Execution

  • Manual Generation:
    php bin/console sylius_feed:generate <feed-id>
    
  • Automated via Cron: Add to your server’s crontab:
    * * * * * /usr/bin/php /path/to/your/project/bin/console sylius_feed:generate <feed-id>
    
  • Event-Based Triggers: Listen for 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)
        }
    });
    

4. Data Filtering

  • Use filters to scope feed data (e.g., only products in a specific category or with stock > 0).
  • Example (programmatic):
    $filter = $feed->getFilter();
    $filter->addCondition('product.category', 'IN', ['electronics', 'clothing']);
    $filter->addCondition('product.onHand', '>', 0);
    

5. Storage & Delivery

  • Local Filesystem: Default storage is public/feeds/. Configure via config/packages/setono_sylius_feed_plugin.yaml:
    setono_sylius_feed_plugin:
        storage:
            type: local
            directory: '%kernel.project_dir%/public/feeds'
    
  • Remote Storage (Flysystem): Configure for AWS S3, FTP, etc.:
    setono_sylius_feed_plugin:
        storage:
            type: flysystem
            service_id: my_flysystem_service
    

Integration Tips

1. Custom Feed Types

  • Extend the plugin to support new feed formats (e.g., 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;
        }
    }
    
  • Register the service:
    services:
        app.feed_type.facebook_catalog:
            class: App\FeedType\FacebookCatalogFeedType
            tags:
                - { name: sylius_feed.feed_type }
    

2. Custom Transformers

  • Add logic to transform data before export (e.g., format prices, clean text):
    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, '.', '');
        }
    }
    
  • Register in config/packages/setono_sylius_feed_plugin.yaml:
    setono_sylius_feed_plugin:
        transformers:
            price: App\Transformer\PriceTransformer
    

3. Webhook Notifications

  • Trigger external actions (e.g., ping a CDN or notify a service) after feed generation:
    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()]
            ]);
        }
    });
    

4. Testing Feeds

  • Use the sylius_feed:generate command with --dry-run to preview output:
    php bin/console sylius_feed:generate <feed-id> --dry-run
    
  • Validate against schema using PHP:
    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()
    ]);
    

Gotchas and Tips

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky