Sylius offers flexible catalog promotions that allow dynamic product price adjustments per sales channel. This guide shows you how to create a custom catalog promotion action that sets a fixed price for products based on the channel. You will integrate the following components:
Custom price calculator logic
Admin form integration
By the end of this guide, you will have a fully integrated catalog promotion action within the Sylius Admin Panel and API.
1. Create the Price Calculator Service
The price calculator determines the new price for each product variant per channel using your custom logic.
This form enables the admin to set a fixed price for each channel:
<?php
// src/Form/Type/FixedPriceConfigurationType.php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Sylius\Bundle\MoneyBundle\Form\Type\MoneyType;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\GreaterThan;
final class FixedPriceConfigurationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('price', MoneyType::class, [
'label' => 'Price',
'currency' => $options['currency'],
'constraints' => [
new NotBlank(['message' => 'Price must be set']),
new GreaterThan(['value' => 0, 'message' => 'Price must be greater than 0']),
],
]);
}
public function configureOptions($resolver): void
{
$resolver
->setRequired(['currency'])
->setAllowedTypes('currency', 'string');
}
public function getBlockPrefix(): string
{
return 'app_catalog_promotion_action_fixed_price_configuration';
}
}
ChannelBasedFixedPriceActionConfigurationType Form
This form handles the configuration of fixed prices for each channel:
<?php
// src/Form/Type/CatalogPromotionAction/ChannelBasedFixedPriceActionConfigurationType.php
namespace App\Form\Type\CatalogPromotionAction;
use Symfony\Component\Form\AbstractType;
use Sylius\Bundle\CoreBundle\Form\Type\ChannelCollectionType;
use Sylius\Component\Core\Model\ChannelInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class ChannelBasedFixedPriceActionConfigurationType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'entry_type' => FixedPriceConfigurationType::class,
'entry_options' => fn(ChannelInterface $channel) => [
'label' => $channel->getName(),
'currency' => $channel->getBaseCurrency()->getCode(),
],
]);
}
public function getParent(): string
{
return ChannelCollectionType::class;
}
}
3. Configure Translations
Add the necessary translation labels for your custom action.
Add Translation for Action Type
In the translations/messages.en.yaml file, define the label for your fixed price action:
sylius:
ui:
fixed_price: 'Fixed Price'
4. Custom Validation (Optional)
✅ Result
You can now select "Fixed Price" as a action type when creating or editing catalog promotions.
If your catalog promotion is not active, make sure the Messenger worker is active: