The future is agentic.

Tutorials

Your promotions, your rules: a deep dive into Commerce Layer’s Rules Engine.

Build powerful, custom promotions with Commerce Layer's Rules Engine and model any complex discount logic with full flexibility. The Rules Engine is now out of beta and available as an add-on.

SB
Sara
· December 19, 2025

Every business has its own rules, discount structures, and customer policies that are built in a peculiar way and can’t always be accommodated with a simple rule. More and more brands are asking for the ability to build their own logic when it comes to promotion management. That’s why we built the Rules Engine — a powerful tool that lets you model even the most complex promotional logic.


As your business grows, your discount strategies often become more sophisticated. You may need to calculate promotions that go beyond a simple percentage or fixed amount discount. Perhaps you want to combine multiple attributes such as SKU properties (tags, metadata, etc.), customer groups, order history, apply special rounding, calculate dynamic bundles or any combination of these.

That’s where the Rules Engine comes in — a powerful new product (available on request) that gives you unprecedented flexibility and control over promotions and pricing. It enables you to define dynamic conditions that go far beyond standard coupon or percentage-based rules.

With the Rules Engine, you can:

  • Build flexible promotions
    They can be based on any attribute — including SKUs, line items, customers, or orders — and will be applied directly at the cart level.
  • Create conditional pricing
    For example, automatically apply a percentage discount to specific customer segments without configuring separate markets. These rules generate discounted prices for eligible users, rather than applying discounts at checkout.

Imagine setting up pricing rules that reflect your real-world business logic — that’s exactly what the Rules Engine is designed to do.

Real-world examples

Let’s look at a few practical examples of what you can achieve with the Rules Engine.

Basic funcionalities

Our Rules Engine works defining conditions on the order and all the resources connected to the orders: line items, SKUs, customers, amounts, shipping methods, payment methods, addresses, prices, inventories, quantitites. And combination of them. There are infinite use cases that can be covered, all with a nice UI.

Let’s assume you need to create a promotion that gives your clients 20% if they buy T-shirts (that should belong to the "new collection" and not to the "outlet collection") and 30% if they buy "shorts", but only for customers that are registered. This will roll-out in a promotion with two different conditions and two different actions: let's see how in the video below:

Promotion based on the reference price

Imagine a scenario where you’ve sent out a voucher offering a 30% discount on polos. If the SKU is priced at €100, when the customer redeems the promotion pays €70. Later, during the sales period, the product price drops to €80 — but you still want the voucher to make the product cost €70, not apply another 30% discount.

With the Rules Engine the solution is easy — you can create promotions that calculate discounts relative to the original reference price ("compare at", usually displayed as a strikethrough), not the current sale price. This ensures your promotion logic remains consistent:

{
  "rules": [
    {
      "id": "f78399cc-6746-400f-b1ca-915082e49ce1",
      "name": "30% discount on Polos",
      "actions": [
        {
          "type": "percentage",
          "value": 0.3,
          "groups": [
            "discountable_items"
          ],
          "apply_on": "compare_at_amount_cents",
          "selector": "order.line_items"
        }
      ],
      "conditions": [
        {
          "field": "order.line_items.sku.tags.id",
          "group": "discountable_items",
          "value": {
            "in_or": [
              "NJkkxfOeJX"
            ]
          },
          "matcher": "array_match"
        }
      ]
    }
  ]
}

Discounted prices for employees

In some companies, employees have the right to get a certain discount on the actual products. Instead of creating a separated website and market with a dedicated price list in Commerce Layer, you can choose to apply a simple 30% discount rule on the prices for users that have a certain email. This will mean that your employee will see the full prices when entering the website, and will see the discounted prices after they log in.

A simple way of handling a discount that can also be limited in time as shown in the example:

{
  "rules": [
    {
      "name": "Discounted Price for employees",
      "actions": [
        {
          "groups": [],
          "type": "percentage",
          "value": 0.3,
          "selector": "price"
        }
      ],
      "conditions": [
        {
          "field": "price.jwt_customer.email",
          "matcher": "end_with",
          "value": "@test.com"
        }
      ]
    }
  ]
}

Bundle promotion: buy a T-shirt, a polo and a top — get 10% off

Bundles are a classic ecommerce strategy. Commerce Layer already supports bundles out of the box, but sometimes you might prefer to implement them as promotions instead — quicker and easier to handle.

With the Rules Engine, you can easily define a rule that pairs products using shared tags and applies a fixed discount to the total price. If the order contains more possible combinations (2 T-shirts, 1 polo and 1 top for example) you can dedice wheter to discount the cheapest or the most expansive one.

Here’s an example:

{
  "rules": [
    {
      "id": "678092bf-100a-4e1b-9534-e8c960f79ac3",
      "name": "Get 10% if you have a bundle of tshirt, polo and top",
      "actions": [
        {
          "type": "percentage",
          "value": 0.1,
          "bundle": {
            "sort": {
              "attribute": "unit_amount_cents",
              "direction": "asc"
            },
            "type": "balanced"
          },
          "groups": [
            "group_a",
            "group_b",
            "group_c"
          ],
          "selector": "order.line_items"
        }
      ],
      "conditions": [
        {
          "field": "order.line_items.sku.tags.name",
          "group": "group_a",
          "value": {
            "in_or": [
              "tshirt"
            ]
          },
          "matcher": "array_match"
        },
        {
          "field": "order.line_items.sku.tags.name",
          "group": "group_b",
          "value": {
            "in_or": [
              "polo"
            ]
          },
          "matcher": "array_match"
        },
        {
          "field": "order.line_items.sku.tags.name",
          "group": "group_c",
          "value": {
            "in_or": [
              "top"
            ]
          },
          "matcher": "array_match"
        }
      ]
    }
  ]
}

Progressive discount: the more you buy, the more you save

Sometimes you may want to increase or decrease the discount based on how many products the customers are buying. For example:

  • Buy 2 products among a list — get 300 USD off
  • Buy 3 products among a list — get 400 USD off

With the Rules Engine, setting up a tiered discount like this is simple. You can define thresholds based on quantities or order totals, and apply progressive rewards that encourage higher-value purchases:

{
  "rules": [
    {
      "id": "trp7685f-7760-452e-b9b4-83434b89e2a8",
      "name": "Buy 2 items among Washing Mashine, stove and microvawe, get 300 USD discount, buy 3 get 400 USD",
      "conditions_logic": "or",
      "conditions": [
        {
          "field": "order.line_items.sku.metadata.kind",
          "matcher": "is_in",
          "value": [
            "stove",
            "microwave",
            "washing_machine"
          ],
          "group": "300_off",
          "aggregations": [
            {
              "field": "order.line_items.sku.metadata.brand",
              "operator": "count_uniq",
              "matcher": "eq",
              "value": 1
            },
            {
              "field": "order.line_items.quantity",
              "operator": "sum",
              "matcher": "eq",
              "value": 2
            }
          ]
        },
        {
          "field": "order.line_items.sku.metadata.kind",
          "matcher": "is_in",
          "value": [
            "stove",
            "microwave",
            "washing_machine"
          ],
          "group": "400_off",
          "aggregations": [
            {
              "field": "order.line_items.sku.metadata.brand",
              "operator": "count_uniq",
              "matcher": "eq",
              "value": 1
            },
            {
              "field": "order.line_items.quantity",
              "operator": "sum",
              "matcher": "eq",
              "value": 3
            }
          ]
        }
      ],
      "actions": [
        {
          "type": "fixed_amount",
          "selector": "order",
          "groups": [
            "300_off"
          ],
          "value": 30000
        },
        {
          "type": "fixed_amount",
          "selector": "order",
          "groups": [
            "400_off"
          ],
          "value": 40000
        }
      ]
    }
  ]
}

Why it matters

The Rules Engine gives enterprise brands the power to express their real promotional strategies — no workarounds, no extra markets, no hacks. Whether you’re rewarding loyal customers, managing employee pricing, or running seasonal campaigns, your logic can now live directly in Commerce Layer.

Try It Out

If you want to start experimenting with advanced promotion logic, request a free trial period directly from your Dashboard in the Promotions app. We’ll help you get started with the Rules Engine and tailor it to your business needs.