# Discount all the SKU in an order based on the shipping country

This rule applies a discount to all the products present in an order if shipped to a specific country. The country code of the shipping address associated with the order is checked and a percentage discount is applied to all the line items associated with an SKU 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": "Shipping address country code DE",
      "conditions": [
        {
          "field": "order.shipping_address.country_code",
          "matcher": "eq",
          "value": "DE"
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order.line_items.sku",
          "value": 0.2
        }
      ]
    }
  ]
} 
```

{% endtab %}

{% tab title="Order" %}

```json
{
  "order": {
    "id": "oKkhYLlzgE",
    "shipping_address": {
      "country_code": "DE",
      "id": "drQLugLEvL"
    },
    "line_items": [
      {
        "quantity": 1,
        "id": "gnYtPpKLeG"
      },
      {
        "quantity": 7,
        "id": "wLGtgmdLjJ",
        "sku": {
          "id": "ZXxPSkbpNP"
        }
      },
      {
        "quantity": 1,
        "id": "zbZtmarXKR1",
        "sku": {
          "id": "WVyPSgRwxd"
        }
      },
      {
        "quantity": 1,
        "id": "zbZtmarXKR2",
        "sku": {
          "id": "WVyPSgRwxZ"
        }
      },
      {
        "quantity": 1,
        "id": "aoMtJlQlxD",
        "sku": {
          "id": "WKjRSMmlxe"
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Outcomes" %}

```json
[
  {
    "id": "9dbbe544-e191-4506-aed5-9d0ca1d25cbd",
    "name": "Shipping address country code DE",
    "priority": 0,
    "match": true,
    "conditions_logic": "and",
    "conditions": [
      {
        "field": "order.shipping_address.country_code",
        "matcher": "eq",
        "value": "DE",
        "group": "18f92feb-04cc-426e-a7cd-0890089b3652",
        "match": true,
        "scope": "any",
        "matches": [
          {
            "order": "oKkhYLlzgE",
            "shipping_address": "drQLugLEvL",
            "group": "18f92feb-04cc-426e-a7cd-0890089b3652"
          }
        ]
      }
    ],
    "actions": [
      {
        "resources": [
          {
            "resource_type": "line_items",
            "id": "wLGtgmdLjJ",
            "group": "18f92feb-04cc-426e-a7cd-0890089b3652",
            "quantity": 7,
            "value": 0.2,
            "action_type": "percentage"
          },
          {
            "resource_type": "line_items",
            "id": "zbZtmarXKR1",
            "group": "18f92feb-04cc-426e-a7cd-0890089b3652",
            "quantity": 1,
            "value": 0.2,
            "action_type": "percentage"
          },
          {
            "resource_type": "line_items",
            "id": "zbZtmarXKR2",
            "group": "18f92feb-04cc-426e-a7cd-0890089b3652",
            "quantity": 1,
            "value": 0.2,
            "action_type": "percentage"
          },
          {
            "resource_type": "line_items",
            "id": "aoMtJlQlxD",
            "group": "18f92feb-04cc-426e-a7cd-0890089b3652",
            "quantity": 1,
            "value": 0.2,
            "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 `country_code` attribute of the shipping address associated with the order is equal to `DE`. (i.e. if the items in the order are going to be shipped to Germany)

#### Actions

The only action in the rule applies a 20% discount to the order's line items that are associated with an SKU.

## Resource payload analysis

The payload contains an order with a shipping address where the country code is `DE`. This matches the condition specified in the rule, confirming that the order qualifies for the discount. The order contains 5 line items, 4 of which (`wLGtgmdLjJ`, `zbZtmarXKR1`, `zbZtmarXKR2`, and `aoMtJlQlxD`) are associated with an SKU (`ZXxPSkbpNP`, `WVyPSgRwxd`, `WVyPSgRwxZ`, and `WKjRSMmlxe` respectively).

## Outcomes check

The outcomes reflect the evaluation of the rules against the resource payload. Since the order's shipping address satisfies the condition, the the rule matches successfully (`match` is `true`) and the order and related shipping address IDs are listed within the `matches` array. The action is applied to the line items associated with an SKU with the decimal value of `0.2` corresponding to the specified percentage discount.

## Conclusion

Once checked that the order's shipping country is the desired one, the rule successfully identifies the line items eligible for the discount and applies a 20% discount to each qualifying line item.


---

# 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/use-cases/promotions/get-percentage-discount-by-shipping-country.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.
