> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/rules-engine/use-cases/promotions/get-percentage-discount-quantity-gteq.md).

# Discount items with large stock availability

Rule breakdown, resource payload analysis, and outcomes explanation

This rule applies a discount to specific line items in an order based on their quantity. The inventory of all the order's line item associated with an SKU is checked and a percentage discount is applied to those whose stock quantity is greater than or equal to a specific value.

The example below is based on the following reference JSONs. Once the rules are evaluated against the resource payload, the outcomes show if and how the conditions are matched and the related actions applied.

{% tabs %}
{% tab title="Rules" %}

```json
{
  "rules": [
    {
      "name": "Discount 5% on items that have a big stock",
      "conditions": [
        {
          "field": "order.line_items.sku.inventory.quantity",
          "matcher": "gteq",
          "value": 100,
          "group": "discountable-items"
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order.line_items",
          "groups": [
            "discountable-items"
          ],
          "value": 0.05
        }
      ]
    }
  ]
} 
```

{% endtab %}

{% tab title="Order" %}

```json
{
  "order": {
    "id": "oKkhYLlzgE",
    "line_items": [
      {
        "quantity": 1,
        "id": "gnYtPpKLeG"
      },
      {
        "quantity": 1,
        "id": "wLGtgmdLjJ",
        "total_amount_cents": 22000,
        "sku": {
          "id": "ZXxPSkbpNP",
          "inventory": {
            "quantity": 100
          }
        }
      },
      {
        "quantity": 1,
        "id": "qLGtgmdLjC",
        "total_amount_cents": 10000,
        "sku": {
          "id": "HXxPSkbpNA",
          "inventory": {
            "quantity": 200
          }
        }
      },
      {
        "quantity": 1,
        "id": "aLGtgmdLjB",
        "total_amount_cents": 9000,
        "sku": {
          "id": "gXxPSkbpNY",
          "inventory": {
            "quantity": 50
          }
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Outcomes" %}

```json
[
  {
    "id": "a6060404-4760-40bf-875e-2d263f215bbd",
    "name": "Discount 5% on items that have a big stock",
    "priority": 0,
    "match": true,
    "conditions_logic": "and",
    "conditions": [
      {
        "field": "order.line_items.sku.inventory.quantity",
        "matcher": "gteq",
        "value": 100,
        "group": "discountable-items",
        "match": true,
        "matches": [
          {
            "order": "oKkhYLlzgE",
            "line_item": "wLGtgmdLjJ",
            "sku": "ZXxPSkbpNP",
            "group": "discountable-items"
          },
          {
            "order": "oKkhYLlzgE",
            "line_item": "qLGtgmdLjC",
            "sku": "HXxPSkbpNA",
            "group": "discountable-items"
          }
        ],
        "scope": "any"
      }
    ],
    "actions": [
      {
        "resources": [
          {
            "resource_type": "line_items",
            "id": "wLGtgmdLjJ",
            "group": "discountable-items",
            "quantity": 1,
            "value": 0.05,
            "action_type": "percentage"
          },
          {
            "resource_type": "line_items",
            "id": "qLGtgmdLjC",
            "group": "discountable-items",
            "quantity": 1,
            "value": 0.05,
            "action_type": "percentage"
          }
        ]
      }
    ]
  }
]
```

{% endtab %}
{% endtabs %}

## Rules breakdown

The desired results can be achieved with a single rule.

#### Conditions

The only condition in the rule checks if the order contains line items associated with SKUs whose stock quantity is greater than or equal to `100`. The line items that match the condition are grouped as `discountable-items`.

#### Actions

The only action in the rule applies a 5% discount to the order's line items that match the condition (i.e. the ones belonging to the `discountable-items` group).

## Resource payload analysis

The provided payload contains an order with 4 line items 3 of which are associated with an SKU. 2 of those SKUs (`ZXxPSkbpNP` and `HXxPSkbpNA`, associated with the line items `wLGtgmdLjJ` and `qLGtgmdLjC`) have a `quantity` that matches or exceeds the desired threshold (`200` and `100` respectively), thus qualifying for the discount.

## Outcomes check

The outcomes reflect the evaluation of the rules against the resource payload. Since the order contains at least one line item that satisfies the condition, the rule matches successfully (`match` is `true`). The two line item IDs (together with the IDs of the related SKUs and the ID of the order) to which the discount is applied are listed within the `matches` array. The action is applied to those line items with the decimal value of `0.05` corresponding to the specified percentage discount.

## Conclusion

The rule successfully identifies the line items eligible for the discount and applies a 5% discount to each qualifying line item.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.commercelayer.io/rules-engine/use-cases/promotions/get-percentage-discount-quantity-gteq.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
