Fixed amount

How the fixed amount 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 fixed_amount enable you to apply a a fixed discount to the unit amount of a specific field.

When setting up a fixed amount 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 integer number corresponding to the amount in cents to be discounted (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 "fixed_amount".

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

discount_mode

String

Learn more here.

limit

Object

Cannot be set when using bundles.

value

Integer

Example

The following action applies a 2000 cents fixed discount to the unit amount of all the line items associated with an SKU among the ones grouped as default-discount within the related condition matchers and distributes a 6000 cents discount over all the line items associated with an SKU among the ones grouped as distributed-discount within the related condition matchers:

"actions": [
  {
    "type": "fixed_amount",
    "selector": "order.line_items.sku",
    "groups": [ "default-discount" ],
    "value": 2000,  
  },
  {
    "type": "fixed_amount",
    "selector": "order.line_items.sku",
    "discount_mode": "distributed",
    "groups": [ "distributed-discount" ],
    "value": 10000,  
  }
]

Value

The amount to be discounted is defined by the value key which must be provided in cents (e.g. 1500 applied to an order with currency code EUR corresponds to a 15€ discount).

Discount mode

By default fixed amount actions use the number specified in the value key as the fixed amount in cents to be discounted from the unit amount of each selected item. You can override this behavior by setting the discount_mode key to distributed. This way the amount to be discounted will be proportionally distributed on the targeted items based on their total amount (i.e. taking into account their unit amount and quantity).

Example

Considering the example above, let's assume that the two targeted groups contain the following items:

The group labeled as default-discount contains 2 line items for a total of 3 units and 22000 cents total amount:

[
  {
    "id": "mnptRLjoXJ",
    "type": "line_items",
    "quantity": 1,
    "unit_amount_cents": 10000,
    "total_amount_cents": 10000,
    "sku": {
      "id": "zTdkkFXdgN",
      "code": "ITEMDEF01"
    }
  },
  {
    "id": "jndtDLsoAM",
    "type": "line_items",
    "quantity": 2,
    "unit_amount_cents": 6000,
    "total_amount_cents": 12000,
    "sku": {
      "id": "xCKdTcQFQH",
      "code": "ITEMDEF02"
    }
  }
]

The discount for each item will be computed as follows:

Default

A fixed amount discount of 2000 cents will be applied to each item's unit amount, corresponding to:

  • ITEMDEF01 — 2000 * 1 = 2000 cents total discount.

  • ITEMDEF02 — 2000 * 2 = 4000 cents total discount.

Distributed

As a first step, the weight of each item's total amount compared to the sum of the total amounts of all the targeted items (20000 cents) is calculated:

  • ITEMDIS01 — 3000 / 20000 = 0.15

  • ITEMDIS02 — 15000 / 20000 = 0.75

  • ITEMDIS03 — 2000 / 20000 = 0.1

As you may expect, the total sum of those weights is 0.15 + 0.75 + 0.1. = 1 .

Then the unit and total discount to apply to each item is computed based on that, proportionally distributing the number specified in the value key of the action (6000):

  • ITEMDIS01 — 6000 * 0.15 = 900 cents of total discount, corresponding to a 900 / 2 = 450 unit discount.

  • ITEMDIS02 — 6000 * 0.75 = 4500 cents of total discount, corresponding to a 900 / 3 = 1500 unit discount.

  • ITEMDIS03 — 6000 * 0.1 = 600 cents of total discount, corresponding to the same unit discount since the item's quantity is 1.

Restrictions

Resources

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

Last updated