How to add a custom catalog promotion scope?
1. Implement a Custom Scope Checker
Register the Checker Service
# config/services.yaml
services:
App\CatalogPromotion\Checker\Variant\InByPhraseScopeChecker:
arguments:
- '@sylius.repository.product_variant'
tags:
- { name: 'sylius.catalog_promotion.variant_checker', type: 'by_phrase' }Create the Checker Class
<?php
// src/CatalogPromotion/Checker/Variant/InByPhraseScopeChecker.php
namespace App\CatalogPromotion\Checker\Variant;
use Sylius\Bundle\CoreBundle\CatalogPromotion\Checker\VariantInScopeCheckerInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Promotion\Model\CatalogPromotionScopeInterface;
use Webmozart\Assert\Assert;
final class InByPhraseScopeChecker implements VariantInScopeCheckerInterface
{
public const TYPE = 'by_phrase';
public function inScope(CatalogPromotionScopeInterface $scope, ProductVariantInterface $productVariant): bool
{
$configuration = $scope->getConfiguration();
Assert::keyExists($configuration, 'phrase');
return str_contains($productVariant->getName(), $configuration['phrase']);
}
}2. Create the Configuration Form Type
Form Type Class and Service
Register the form type:
4. Translations
5. Custom Validation (Optional)
✅ Result


Last updated
Was this helpful?
