PHP code example of setono / sylius-catalog-promotion-plugin

1. Go to this page and download the library: Download setono/sylius-catalog-promotion-plugin 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/ */

    

setono / sylius-catalog-promotion-plugin example snippets



# config/bundles.php

return [
    // ...
    Setono\SyliusCatalogPromotionPlugin\SetonoSyliusCatalogPromotionPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
    // ...
];




use Setono\SyliusCatalogPromotionPlugin\Context\StaticChannelContext;
use Sylius\Component\Channel\Model\ChannelInterface;

class YourFeedProcessor
{
    public function __construct(private readonly StaticChannelContext $staticChannelContext) {
    
    }
    
    public function process(): void
    {
        /**
         * A list of channels you need to process
         * 
         * @var list<ChannelInterface> $channels 
         */
        $channels = [];
        
        foreach ($channels as $channel) {
            $this->staticChannelContext->setChannel($channel);
            
            // do your processing...
        }
    }
}



use Setono\SyliusCatalogPromotionPlugin\Checker\OnSale\OnSaleCheckerInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\ProductInterface;

class YourFeedProcessor
{
    public function __construct(private readonly OnSaleCheckerInterface $onSaleChecker) {
    
    }
    
    public function process(): void
    {
        /**
         * A list of products you are processing
         * 
         * @var list<ProductInterface> $products 
         */
        $products = [];
        
        foreach ($products as $product) {
            if($this->onSaleChecker->onSale($product)) {
                // the product is on sale
            }
        }
    }
}
bash
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate