# Fixed amount

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](#value) 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](/rules-engine/actions.md)):

<table><thead><tr><th>Key</th><th>Type<select multiple><option value="YGgpISUGMdPQ" label="Boolean" color="blue"></option><option value="QePOb3JPIkBd" label="Integer" color="blue"></option><option value="rSmUinI3meTE" label="Float" color="blue"></option><option value="ytg3YoHxHpB2" label="String" color="blue"></option><option value="rlTqes6yAIME" label="Array" color="blue"></option><option value="qhQqnuEfMsvz" label="Object" color="blue"></option></select></th><th data-type="checkbox">Required</th><th>Notes</th></tr></thead><tbody><tr><td><strong><code>type</code></strong></td><td><span data-option="ytg3YoHxHpB2">String</span></td><td>true</td><td>Must be <code>"fixed_amount"</code>.</td></tr><tr><td><strong><code>selector</code></strong></td><td><span data-option="ytg3YoHxHpB2">String</span></td><td>true</td><td></td></tr><tr><td><strong><code>identifier</code></strong></td><td><span data-option="ytg3YoHxHpB2">String</span></td><td>false</td><td>Can be set only if the <code>selector</code> key value is an attribute.</td></tr><tr><td><strong><code>groups</code></strong></td><td><span data-option="rlTqes6yAIME">Array</span></td><td>false</td><td>Required when using <a href="/pages/GhfyTAymk4S8RYeOrEeX">bundles</a>.</td></tr><tr><td><strong><code>bundle</code></strong></td><td><span data-option="qhQqnuEfMsvz">Object</span></td><td>false</td><td></td></tr><tr><td><strong><code>aggregation</code></strong></td><td><span data-option="qhQqnuEfMsvz">Object</span></td><td>false</td><td></td></tr><tr><td><strong><code>apply_on</code></strong></td><td><span data-option="ytg3YoHxHpB2">String</span></td><td>false</td><td></td></tr><tr><td><strong><code>quantity</code></strong></td><td><span data-option="QePOb3JPIkBd">Integer</span></td><td>false</td><td>Learn more <a href="#quantity">here</a>.</td></tr><tr><td><strong><code>discount_mode</code></strong></td><td><span data-option="ytg3YoHxHpB2">String</span></td><td>false</td><td>Learn more <a href="#discount-mode">here</a>.</td></tr><tr><td><strong><code>limit</code></strong></td><td><span data-option="qhQqnuEfMsvz">Object</span></td><td>false</td><td>Cannot be set when using <a href="/pages/GhfyTAymk4S8RYeOrEeX">bundles</a>.</td></tr><tr><td><strong><code>value</code></strong></td><td><span data-option="QePOb3JPIkBd">Integer</span></td><td>true</td><td></td></tr></tbody></table>

### 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:

<pre class="language-json"><code class="lang-json">"actions": [
  {
<strong>    "type": "fixed_amount",
</strong><strong>    "selector": "order.line_items.sku",
</strong>    "groups": [ "default-discount" ],
<strong>    "value": 2000,  
</strong>  },
  {
<strong>    "type": "fixed_amount",
</strong>    "selector": "order.line_items.sku",
<strong>    "discount_mode": "distributed",
</strong>    "groups": [ "distributed-discount" ],
    "value": 10000,  
  }
]
</code></pre>

## 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).

## Quantity

The `quantity` parameter allows you to override the actual quantity of the resource when applying the fixed amount discount action. When specified, the action will be applied to the minimum between the specified quantity value and the actual resource quantity.

This parameter is particularly useful when you need to limit the number of items that receive a discount, regardless of how many units are actually in the cart. The action applies to the specified number of items, while any remaining items beyond that quantity will not receive the discount.&#x20;

{% hint style="info" %}
This parameter affects how many items receive the discount only, not the discount amount itself. For example, if you set it to 2 on a line item with 5 units, only 2 units will receive the fixed amount discount, while the remaining 3 units will be charged at full price.
{% endhint %}

{% hint style="success" icon="gift" %}
To implement a free gift promotion, use the [free gift](/rules-engine/actions/types/free-gift.md) action type, which applies a 100% discount to targeted line items without requiring you to know or hardcode item prices.
{% endhint %}

## 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).&#x20;

### Example

Considering the [example](#example) above, let's assume that the two targeted groups contain the following items:

{% tabs %}
{% tab title="default-discount" %}
The group labeled as `default-discount` contains **2** line items for a total of **3** units and **22000** cents total amount:

```json
[
  {
    "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"
    }
  }
]
```

{% endtab %}

{% tab title="distributed-discount" %}
The group labeled as `distributed-discount` contains **3** line items for a total of **6** units and **20000** cents total amount:

```json
[
  {
    "id": "qOYocnANsO",
    "type": "line_items",
    "quantity": 2,
    "unit_amount_cents": 1500,
    "total_amount_cents": 3000,
    "sku": {
      "id": "PeHfayCvwQ",
      "code": "ITEMDIS01"
    }
  },
  {
    "id": "nlHjpkVpCG",
    "type": "line_items",
    "quantity": 3,
    "unit_amount_cents": 5000,
    "total_amount_cents": 15000,
    "sku": {
      "id": "pHaoUAvTVy",
      "code": "ITEMDIS02"
    }
  },
  {
    "id": "DtZjSMEKvm",
    "type": "line_items",
    "quantity": 1,
    "unit_amount_cents": 2000,
    "total_amount_cents": 2000,
    "sku": {
      "id": "TkhHRotCOA",
      "code": "ITEMDIS03"
    }
  }
]
```

{% endtab %}
{% endtabs %}

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`&#x20;
* `ITEMDIS02` — `15000 / 20000 = 0.75`
* `ITEMDIS03` — `2000 / 20000 = 0.1`

{% hint style="info" %}
As you may expect, the total sum of those weights is `0.15 + 0.75 + 0.1. = 1` .
{% endhint %}

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.&#x20;
* `ITEMDIS02` — `6000 * 0.75 = 4500` cents of total discount, corresponding to a `900 / 3 = 1500` unit discount.&#x20;
* `ITEMDIS03` — `6000 * 0.1 = 600` cents of total discount, corresponding to the same unit discount since the item's quantity is 1.

{% hint style="warning" %}
As you may expect, the total sum of those discounts is `900 + 4500 + 600 = 6000` (i.e. the total discount to be distributed over the targeted items). Being the results of the divisions cut at the second decimal, this may not always be true. If that's the case an additional `±` rounding on the second decimal of the unit discount applied to the targeted item **with less quantity** will be automatically applied to match the total discount to be distributed.
{% endhint %}

## Restrictions

{% hint style="success" %}
Fixed amount actions support [bundles](/rules-engine/actions/bundle.md), provided that one or more groups among the ones defined when grouping the matches of the related conditions are specified. The possibility to set a [discount mode](#discount-mode) different from the default is available for fixed amount actions only.
{% endhint %}

{% hint style="warning" %}
You can set a [limit](/rules-engine/actions/limit.md) on fixed amount actions only if you're **not** using bundles.&#x20;
{% endhint %}

## Resources

{% hint style="info" %}
As regards the Rule Engine [integration with Commerce Layer Core API](/rules-engine/readme.md#core-api-integration), the fixed amount action type is available both for [promotions](/rules-engine/resources/promotions.md) ([order rules](/rules-engine/core-api-integration/order-rules.md)) and [price lists](/rules-engine/resources/price-lists.md) ([price rules](/rules-engine/core-api-integration/price-rules.md)).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.commercelayer.io/rules-engine/actions/types/fixed-amount.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
