Percentage

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

Actions of type percentage enable you to apply a percentage discount to the amount of a specific field.

When setting up a percentage discount action, in addition to the action type, you need to specify at least the attribute or resource on which to apply the action as the selector key value and fill the value key with the float number corresponding to the percentage discount to be applied (for more information on the parameters listed in the table below and how they work please refer to the main actions page):

Key
Type
Required
Notes

type

String

Must be "percentage".

selector

String

identifier

String

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

groups

Array

Required when using bundles.

bundle

Object

aggregation

Object

apply_on

String

round

Boolean

Learn more here.

limit

Object

Cannot be set when using bundles.

value

Float

Example

The following action applies a 20% discount to the amount of all the line items associated with an SKU among the ones grouped as discountable-items within the related condition matchers:

"actions": [
  {
    "type": "percentage",
    "selector": "order.line_items.sku",
    "groups": [ "discountable-items" ],
    "value": 0.2,  
  }
]

Value

The percentage to be discounted is defined by the value key which must be provided in decimal form as a float number between 0 and 1.

Maximum 4 decimals are allowed (e.g. 0.1535 corresponds to a 15.35% discount).

Round

If you want to avoid displaying or dealing with decimal values in discounts or final prices when using percentage discount actions (e.g. to simplify the shopping experience and/or make offers appear cleaner and more user-friendly), you can leverage the round key and set its value to true. This way, the related percentage discounts will be rounded off to the nearest integer.

Please note that the computation of the discount and its rounding logic differ slightly depending on whether the related action is applied to an order rule or to a price rule, as detailed below.

  • Promotions — the rounding happens at the discount level, meaning that the discount amount is calculated and rounded first, then subtracted from the item price.

  • Price lists — the rounding happens at the price level, meaning that the discount amount is calculated and subtracted from the item price first, and the resulting price is then rounded.

Restrictions

Resources

As regards the Rule Engine integration with Commerce Layer Core API, the percentage discount action type is available both for promotions (order rules) and price lists (price rules).

Last updated