Need to create rules based on bundles?
Learn more
LogoLogo
APIsChangelog
  • Getting started
  • Rules
  • Conditions
    • Scope
    • Aggregations
    • Nested
    • Dynamic values
  • Actions
    • Types
      • Percentage
      • Fixed amount
      • Fixed price
      • Buy X pay Y
      • Every X discount Y
    • Bundle
      • Balanced
      • Every
    • Aggregation
    • Limit
  • Matchers
  • Operators
  • Check and validation
  • Core API integration
    • Order rules
    • Price rules
    • Virtual relationships
  • Resources
    • Promotions
    • Price lists
  • Use cases
    • Promotions
      • Discount line items based on item's price
      • Get a discount when paying by credit card
      • Discount an order based on promo item and total number of items
      • Offer a specific shipping method for free in a specific country
      • Discount items with large stock availability
      • Discount all the SKU in an order based on the shipping country
      • Discount all the SKU in an order based on the customer email domain
    • Price lists
      • Discount all prices greater than or equal to a specific value
      • Discount specific SKUs for new clients
      • Change strike-through price based on customer email domain
On this page
  • Example
  • Value
  • Restrictions
  • Resources
  1. Actions
  2. Types

Every X discount Y

How the every X discount Y action works, what are the required and optional parameters to set it up, and the resources for which it's enabled

PreviousBuy X pay YNextBundle

Last updated 2 months ago

Actions of type every_x_discount_y enable you a fixed amount discount of value y on the selected items for each interval defined by the value x on the amount of a desired field. The total discount is proportionally distributed based on the quantity of the selected items.

If X is greater than the amount on which the intervals are supposed to be calculated, the action won't have any effect.

The action applies even when the attribute value isn't an exact multiple of X but just greater than. The discount is proportionally distributed based on the targeted items' quantity.

This way, if the value of the specified field is n (where n is greater than or equal to m*x and less than (m+1)*x, with m greater than zero) the total discount applied will be m*y.

When setting up a every X discount Y action, in addition to the action type, you need to specify at least value object as described (for more information on the parameters listed in the table below and how they work please refer to the main ):

Key
Type
Required
Notes

type

String

Must be "every_x_discount_y".

selector

String

identifier

String

Can be set only if the selector key value is an attribute.

groups

Array

aggregation

Object

value

Object

Example

The following action applies a 5000 cents discount every 30000 cents of the total amount of the order, proportionally distributing the total resulting discount on the line items associated with an SKU belonging to the related condition's matchers grouped as discountable-items:

"actions": [
  {
    "type": "every_x_discount_y",
    "selector": "order.line_items.sku",
    "groups": [ "discountable-items" ],
    "value": {
      "x": 30000,
      "y": 5000,
      "attribute": "total_amount_cents"
    }  
  }
]

Considering some real number:

  • If the total amount of the order is 60000 cents and the order contains two products — both with quantity 1 for a total of 2 units — the total discount applied will be (60000 / 30000) * 5000 = 10000 cents, equally distributed on the two line items (10000 / 2 = 5000 cents each).

  • If the total amount of the order is 90000 cents and the order contains two products — one with quantity 2 and the other with quantity 1 for a total of 3 units — the total discount applied will be (90000 / 30000) * 5000 = 15000 cents, resulting in a 15000 / 3 = 5000 cents discount per units, proportionally distributed on the two line items (5000 * 2 = 10000 cents on the one with quantity 2, 5000 * 1 = 5000 cents on the other).

  • If the total amount of the order is 140000 cents and the order contains three products — one with quantity 5, another with quantity 3, and the other with quantity 2, for a total of 10 units — the total discount applied will be (140000 / 30000) * 5000 = 20000 cents, resulting in a 20000 / 10 = 2000 cents discount per unit, proportionally distributed on the three line items (2000 * 5 = 10000 cents on the one with quantity 5, 2000 * 3 = 6000 cents on the one with quantity 3, 2000 * 2 = 4000 cents on the one with quantity 2).

Please note that when calculating the number of intervals on which to apply the y discount, we always consider only the quotient of the division between the numeric value of the field specified in the attribute and x (skipping the remainder when the former isn't an exact multiple of the latter).

Value

The x and y values of a buy X pay Y are defined within the value object where you can also optionally set a limit on the number of items to consider for the calculation:

Key
Type
Required
Description

x

Integer

The number (usually an amount in cents) that defines the segmentation in intervals.

y

Integer

The amount in cents to be discounted for each interval.

attribute

String

Restrictions

Resources

The field of the main resource (at the moment, orders, since this action is available for only) on which to calculate the intervals, based on the x key (must be numeric).

You cannot use , set a , or on which to apply the action when setting up every X discount Y actions.

As regards the Rule Engine , the every X discount Y action type is available for () only.

actions page
here
order rules
bundles
limit
promotions
order rules
integration with Commerce Layer Core API
target a specific attribute