SyliusCon 2025
Early Bird Deal
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • 📖Sylius Documentation
  • Organization
    • Sylius Team
  • Release Cycle
    • Backwards Compatibility Promise
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • 🎨Frontend & Themes
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Contributing Translations
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
      • How to add a custom translatable model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Templates
    • Customizing Styles
    • Customizing Dynamic Elements
    • Customizing Validation
    • Customizing Menus
    • Customizing Translations
    • Customizing Flashes
    • Customizing State Machines
    • Customizing Grids
    • Customizing Fixtures
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • 🧑‍🍳The Cookbook
  • How to resize images?
  • How to add one image to an entity?
  • How to add multiple images to an entity?
  • How to add a custom cart promotion action?
  • How to add a custom cart promotion rule?
  • Sylius 1.X Documentation
    • 📓Sylius 1.x Documentation
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page
  • Promotion Basics
  • Creating a Promotion Programmatically
  • Promotion Rules
  • Promotion Actions
  • Applying Cart Promotions
  • Applying a Promotion Manually
  • Promotion Filters

Was this helpful?

Edit on GitHub
  1. The Book
  2. Carts & Orders

Cart Promotions

The Cart Promotions system in Sylius is highly flexible, combining promotion rules and actions to create tailored discount programs.

Promotion Basics

Each cart promotion has:

  • A unique code and name.

  • A usage limit: the total number of times it can be used.

  • A validity period: the time frame during which it is active.

  • An exclusivity option: exclusive promotions prevent other promotions from being applied.

  • A priority: used to control the order of application, especially for exclusive promotions.

Promotion priorities are assigned as numbers. Higher numbers indicate higher priority, so a promotion with a priority 3 will be applied before one with a priority 1 Example of Priority Use: Suppose you have two promotions—one for 10% off the entire order and another for a $5 discount. In this case, you might want to apply the 10% discount first to maximize its impact.

Creating a Promotion Programmatically

To create a promotion, use the promotion factory:

/** @var PromotionInterface $promotion */
$promotion = $this->container->get('sylius.factory.promotion')->createNew();
$promotion->setCode('simple_promotion_1');
$promotion->setName('Simple Promotion');

However, a basic promotion needs Rules and Actions to be functional.

Promotion Rules

Promotion rules define the conditions that must be met for a promotion to apply. Each rule has a specific RuleChecker that checks order details, such as:

  • Whether a specific taxon is in the order.

  • If the total price of items in a specific taxon meets a threshold.

  • Whether the order total reaches a specified amount.

  • and more...

Default Promotion Rule Types in Sylius

Cart Quantity

Checks if the cart has a certain number of items

Item Total

Checks if the cart’s item total meets a specified amount

Has at least one from taxons

Ensures the cart includes items from certain taxons

Total price of items from taxon

Ensures items from a specific taxon meet a total price threshold

Nth Order

Checks if the customer is placing their nth order

Shipping Country

Verifies the shipping country matches a specific requirement

Customer Group

Ensures the customer belongs to a certain group

Contains Product

Checks if a specified product is in the order

Creating a Promotion Rule Programmatically

Use the PromotionRuleFactory to create and configure rules.

Example: To set a rule that requires at least 5 items in the cart:

/** @var PromotionRuleFactoryInterface $ruleFactory */
$ruleFactory = $this->container->get('sylius.factory.promotion_rule');
$quantityRule = $ruleFactory->createCartQuantity('5');
$promotion->addRule($quantityRule);

Rules define eligibility conditions only. To apply discounts, actions are required.

Promotion Actions

Promotion actions define what happens when promotion rules are met. Actions include various types of discounts:

  • Fixed Order Discount: e.g., $5 off the order total.

  • Percentage Order Discount: e.g., 10% off the entire order.

  • Fixed Unit Discount: e.g., $1 off each unit.

  • Percentage Unit Discount: e.g., 10% off each unit.

  • Shipping Percentage Discount: e.g., 10% off shipping costs.

Actions affect all items in the order by default. To apply discounts to specific items only, use filters.

Creating a Promotion Action Programmatically

Use the PromotionActionFactory to create actions. For example, to set a fixed discount of $10:

/** @var PromotionActionFactoryInterface $actionFactory */
$actionFactory = $this->container->get('sylius.factory.promotion_action');
$action = $actionFactory->createFixedDiscount(10);
$promotion->addAction($action);

After configuring rules and actions, save the promotion to the repository:

$this->container->get('sylius.repository.promotion')->add($promotion);

Applying Cart Promotions

The PromotionProcessor manages the application of cart promotions:

  1. Reverts any existing promotions on the order.

  2. Checks the eligibility of all available promotions for the order.

  3. Applies eligible promotions.

Applying a Promotion Manually

To apply a 10% discount programmatically:

/** @var PromotionInterface $promotion */
$promotion = $this->container->get('sylius.factory.promotion')->createNew();
$promotion->setCode('discount_10%');
$promotion->setName('10% discount');

/** @var PromotionActionFactoryInterface $actionFactory */
$actionFactory = $this->container->get('sylius.factory.promotion_action');
$action = $actionFactory->createPercentageDiscount(10);

$promotion->addAction($action);
$this->container->get('sylius.repository.promotion')->add($promotion);

// Apply the promotion to an order
$this->container->get('sylius.promotion_applicator')->apply($order, $promotion);

Promotion Filters

PreviousAdjustmentsNextCoupons

Last updated 7 months ago

Was this helpful?

Filters allow actions to target specific groups of products. For example, use a to apply a promotion only to items within a specific taxon.

Check on promotion filters to have a better understanding of them.

TaxonFilter
these scenarios