Need to create rules based on bundles?
Learn more
LogoLogo
APIsChangelog
  • Getting started
  • Rules
  • Conditions
    • Scope
    • Aggregations
    • Nested
    • Dynamic values
  • Actions
    • Types
      • Percentage
      • Fixed amount
      • Fixed price
      • Buy X pay Y
      • Every X discount Y
    • Bundle
      • Balanced
      • Every
    • Aggregation
    • Limit
  • Matchers
  • Operators
  • Check and validation
  • Core API integration
    • Order rules
    • Price rules
    • Virtual relationships
  • Resources
    • Promotions
    • Price lists
  • Use cases
    • Promotions
      • Discount line items based on item's price
      • Get a discount when paying by credit card
      • Discount an order based on promo item and total number of items
      • Offer a specific shipping method for free in a specific country
      • Discount items with large stock availability
      • Discount all the SKU in an order based on the shipping country
      • Discount all the SKU in an order based on the customer email domain
    • Price lists
      • Discount all prices greater than or equal to a specific value
      • Discount specific SKUs for new clients
      • Change strike-through price based on customer email domain
On this page
  • Rules breakdown
  • Resource payload analysis
  • Outcomes check
  • Conclusion
  1. Use cases
  2. Promotions

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

Rule breakdown, resource payload analysis, and outcomes explanation

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.

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

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.

PreviousDiscount items with large stock availabilityNextDiscount all the SKU in an order based on the customer email domain

Last updated 2 months ago