Free gift

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

Actions of type free_gift enable you to apply a 100% discount to specific line items that have been added to the cart as free gifts. Unlike other action types, they target line items directly by their IDs and the action distributes a discount budget across them in priority order.

When setting up a free gift action, in addition to the action type, you must specify which line items are eligible via the identifiers object and optionally cap the total number of discounted units via the quantity key (for more information on any 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 "free_gift".

identifiers

Object

Learn more here.

quantity

Integer

Learn more here.

circle-exclamation

Example

The following action applies a 100% discount to up to 2 units of line items matching any of the provided SKU or bundle list identifiers (i.e. if the cart contains the SKUs identified by the WKyPSgRwxY or VCxRGsExyZ IDs, or the bundle identified by the ABcDEfGhXy ID):

"actions": [
  {
    "type": "free_gift",
    "identifiers": {
      "order.line_items.sku.id": [ "WKyPSgRwxY", "VCxRGsExyZ" ],
      "order.line_items.bundle.id": [ "ABcDEfGhXy" ]
    },
    "quantity": 2
  }
]
circle-check

Free promo detector

Identifiers

The identifiers object maps selector paths keys to arrays of IDs values. Any line item matching at least one selector / ID pair becomes eligible for the free gift discount. At least one key must be present, and each value must be a non-empty array of strings.

The currently allowed selector paths are:

Key
Type
Description

order.line_items.sku.id

Array

Matches line items by SKU ID (i.e. if the cart contains at least one of the SKU listed in the array).

order.line_items.bundle.id

Array

Matches line items by bundle ID (i.e. if the cart contains at least one of the bundle listed in the array).

order.line_items.sku.sku_lists.id

Array

Matches line items by SKU list ID (i.e. if the cart contains at least one of the SKU belonging to the provided SKU lists).

circle-exclamation

Quantity

The quantity parameter defines the total number of units that will receive a 100% discount, distributed across all matching line items. It defaults to 1 if not specified.

When multiple line items match, the engine assigns the discount budget in a fixed priority order based on:

  1. Keys — identifier keys are processed in the order they appear in the identifiers object.

  2. IDs — within each key, IDs are processed in the order they appear in the array.

  3. Line items — when multiple line items match the same selector / ID pair, they are processed in the order they appear in the cart.

The budget is decremented as units are assigned. Once the full quantity value has been allocated, any remaining matching line items receive no discount.

circle-info

This parameter controls how many units receive the discount in total, not which items are eligible. For example, if quantity is 2 and three matching line items each have a quantity of 1, only the first two in priority order will be discounted — the third won't.

Restrictions

circle-exclamation

Resources

circle-info

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

Last updated