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 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.

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

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.

PreviousOffer a specific shipping method for free in a specific countryNextDiscount all the SKU in an order based on the shipping country

Last updated 2 months ago