Docs
Store operations
Promotions
Examples
Using logical operators

Code Samples for Promotions that Use Logical Operators

Buy two of product X or buy two of product Y (OR operator)

The following promotion uses the logical OR operator at item matcher level. Each of the following combinations satisfies the condition:

  • 1 product X + 1 product Y
  • 2 product X
  • 2 product Y
Example request
{
  "name": "Buy two of product X or buy two of product Y",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "condition": {
        "cart": {
          "items": {
            "or": [
              {
                "products": [
                  118
                ]
              },
              {
                "variants": [
                  134
                ]
              }
            ]
          },
          "minimum_quantity": 2
        }
      },
      "action": {
        "gift_item": {
          "product_id": 130,
          "quantity": 1
        }
      }
    }
  ],
  "notifications": [
    {
      "type": "UPSELL",
      "content": "<div>&nbsp;</div>",
      "locations": [
        "CART_PAGE"
      ]
    },
    {
      "type": "ELIGIBLE",
      "content": "<div>&nbsp;</div>",
      "locations": [
        "CART_PAGE"
      ]
    },
    {
      "type": "APPLIED",
      "content": "<div>&nbsp;</div>",
      "locations": [
        "CART_PAGE"
      ]
    }
  ],
  "stop": false,
  "start_date": "2019-02-01T05:00:00+00:00",
  "status": "ENABLED"
}

Get percentage off X category, excluding an item (AND, NOT operators)

Example request
{
  "name": "Get 20% off all kitchen items, excluding Able Brewing System",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "action": {
        "cart_items": {
          "items": {
            "and": [
              {
                "categories": [
                  25
                ]
              },
              {
                "not": {
                  "products": [
                    129
                  ]
                }
              }
            ]
          },
          "discount": {
            "percentage_amount": "20"
          }
        }
      },
      "apply_once": true
    }
  ]
}

Get X% off all brand X, except X products in brand Y (OR, AND, NOT operators)

Example request
{
  "name": "Get 20% off all coffee makers except for those using new arrivals coffee filters",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "action": {
        "cart_items": {
          "items": {
            "or": [
              {
                "and": [
                  {
                    "brands": [
                      37
                    ]
                  },
                  {
                    "categories": [
                      25
                    ]
                  }
                ]
              },
              {
                "and": [
                  {
                    "brands": [
                      38
                    ]
                  },
                  {
                    "categories": [
                      35
                    ]
                  },
                  {
                    "not": {
                      "categories": [
                        24
                      ]
                    }
                  }
                ]
              }
            ]
          },
          "discount": {
            "percentage_amount": "20"
          }
        }
      },
      "apply_once": true,
      "currency_code": "AUD"
    }
  ]
}

X% off storewide except product Y or product Z or any items in category C

Example request
{
  "name": "10% off storewide except 'Able Brewing System' or 'Chemex Coffeemaker' or any garden products",
  "redemption_type": "AUTOMATIC",
  "rules": [
    {
      "action": {
        "cart_items": {
          "discount": {
            "percentage_amount": 10
          },
          "items": {
            "and": [
              {
                "not": {
                  "products": [
                    129,
                    130                 ]
                }
              },
              {
                "not": {
                  "categories": [
                    24
                  ]
                }
              }
            ]
          }
        }
      },
      "apply_once": true
    }
  ]
}
Did you find what you were looking for?