> 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-promo-item-number-of-items-gteq.md).

# Discount an order based on promo item and total number of items

Rule breakdown, resource payload analysis, and outcomes explanation

This rule applies a discount to an order based on which items it contains and how many. All the order's line item SKU codes are checked to find a specific promotional product. The total number of SKUs in the order is also checked. A percentage discount is applied to the order's total amount if the conditions are met.

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": "Get 10% discount on the whole order if a specific SKU is present",
      "conditions": [
        {
          "field": "order.line_items.sku.code",
          "matcher": "eq",
          "value": "PROMOTSHIRT"
        },
        {
          "field": "order.skus_count",
          "matcher": "gteq",
          "value": 3
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order",
          "value": 0.1
        }
      ]
    }
  ]
} 
```

{% endtab %}

{% tab title="Order" %}

```json
{
  "order": {
    "id": "oXkhYLlzgE",
    "line_items": [
      {
        "id": "dKdhYLlzgE",
        "sku": {
          "id": "dKfhgdlzgE",
          "code": "PROMOTSHIRT"
        }
      },
      {
        "id": "eKfhYFkztQ",
        "sku": {
          "id": "sDfhYFkcfR",
          "code": "BLACKHOODIEM"
        }
      },
      {
        "id": "eYfhYSkzwE"
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Outcomes" %}

```json
[
  {
    "id": "83a8c59a-6bb2-446a-8d51-025c047050bd",
    "name": "Get 10% discount on the whole order if a specific SKU is present",
    "priority": 0,
    "match": false,
    "conditions_logic": "and",
    "conditions": [
      {
        "field": "order.line_items.sku.code",
        "matcher": "eq",
        "value": "PROMOTSHIRT",
        "group": "93316c65-9c15-45bb-b84b-baca142b3636",
        "match": true,
        "matches": [
          {
            "order": "oXkhYLlzgE",
            "line_item": "dKdhYLlzgE",
            "group": "93316c65-9c15-45bb-b84b-baca142b3636"
          }
        ],
        "scope": "any"
      },
      {
        "field": "order.skus_count",
        "matcher": "gteq",
        "value": 3,
        "group": "93316c65-9c15-45bb-b84b-baca142b3636",
        "match": false,
        "matches": [

        ],
        "scope": "any"
      }
    ],
    "actions": [

    ]
  }
]
```

{% endtab %}
{% endtabs %}

## Rules breakdown

The desired results can be achieved with a single rule.

#### Conditions

The rule contains two conditions:

1. The first condition checks if the order contains a line item associated with an SKU whose code is `PROMOTSHIRT`.
2. The second condition checks if the order contains at least 3 SKUs by inspecting the `skus_count` attribute.

Since no `conditions_logic` is specified, the default value `and` will be used.

#### Actions

The only action in the rule applies a 10% discount to the whole order amount if both the conditions are met.

## Resource payload analysis

The provided payload contains an order with 3 line items of which only 2 (`dKdhYLlzgE` and `eKfhYFkztQ`) are associated with an SKU code (`PROMOTSHIRT` and `BLACKHOODIEM` respectively). Hence the order contains the promotional product (i.e. it matches the first condition) but doesn't reach the minimum number of SKUs in total to match the second condition.

## Outcomes check

The outcomes reflect the evaluation of the rules against the resource payload. Since the order's payment source satisfies only one of the two conditions, the rule doesn't match (`match` is `false`). The first condition is met and the IDs of the order and of the line item associated with the promotional product are listed within the related `matches` array. The second condition isn't met so the related `matches` array is empty. Consequently, the `actions` array is also empty and the desired action is not applied.

## Conclusion

The rule doesn't match the provided order payload. Consequently, even if the promotional product is present, no discount is applied due to the total number of SKUs in the order being under the specified threshold.


---

# 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-promo-item-number-of-items-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.
