Skip to main content

Different discounts for different categories

Prerequisites
Before you start, ensure you:
  1. Create your Integration API key.
  2. If you haven't done so already, fork our Sample Campaigns collection in Postman: Run in Postman.
  3. In the Campaign Manager, open the EASY-DISCOUNT: Specific discounts on categories demo campaign and click Activate Campaign.
  4. Open the Rule Builder to get some context.

Let's create a promotion rule that gives a discount only on products that are part of a specific category, for example, Road Bikes or Helmets. This campaign relies on the cart filter feature to select the items that are part of the requested category.

Creating the discount promotion

Cart item filters

Let's start by creating the cart item filters. We will discount road bikes by 40% if we find 1 in the session and helmets by 10% if we find more than 2, so we create 2 filters:

  1. Click Add Filter.
  2. Click Add Filter Step and select Filter items by condition.
  3. Set the filter to Item category (Item) is equal to Road Bikes.
  4. In Save As, type RoadBikes and click Save Filter.

This creates the RoadBikes filter and we also get the RoadBikes item count (RoadBikes) filter created automatically, which returns the amount of items in the cart item filter.

Repeat these steps for the Helmets category. This procedure also creates the Helmets item count (Helmets) filter. The category of each item is provided by your shop system via the Integration API.

Rule 1: Checking the helmets

Condition

  1. Name the rule 10% off Category Helmets.
  2. Click Add condition and select Check attribute value with the following expression: Helmets item count (Helmets) is greater than or equal to 2.

Effect

Because we do not want to discount the whole session but rather specific items, we use the Discount individual items effect:

  1. Set the List of items to Helmets.
  2. Set the Discount name to 10% off helmets.
  3. Set the Discount value to (Quantity of item (Item)*Price of item (Item)) * 10%.

Rule 2: Checking the bikes

Repeat the previous section for the road bikes:

  1. Select the RoadBikes item count (RoadBikes) for the condition.
  2. Select RoadBikes in the effect.
  3. Set the discount value to: (Quantity of item (Item)*Price of item (Item)) * 40%.

These 2 effects are applied every time the condition is true.

Running the campaign

To run the campaign, use the following payload sent to the Integration API's Update customer session endpoint:

Let's trigger our campaign by inserting 2 cart items in the session and ensuring the session is closed:

  • Line 12: The item is part of the Road Bikes category.
  • Line 22: The other item is part of the Helmets category.
  • Line 20: This item has 2 units.
Sending a session update
CURL -X PUT https://mycompany.europe-west1.talon.one/v2/customer_sessions/my_session_id -d
'{
"customerSession": {
"profileId": "CHP75036CF3",
"state": "closed",
"cartItems": [
{
"name": "ProductC",
"sku": "sku-00003",
"quantity": 1,
"price": 200,
"Category": "Road Bikes",
"weight": 0,
"position": 0,
"attributes": {}
},
{
"name": "ProductD",
"sku": "sku-00004",
"quantity": 2,
"price": 30,
"Category": "Helmets",
"weight": 0,
"position": 1,
"attributes": {}
}
],
"couponCodes": [
""
],
"referralCode": "",
"attributes": {},
"additionalCosts": {}
},
"responseContent": []
}'
Key Takeaways
  • You can have several rules in a campaign. They are all evaluated.
  • You can select specific items from the session and save them in a list of items thanks to a cart item filter.
  • Some effects can be applied to specific lists of cart items, such as the Discount individual items effect.
  • The category of an item is passed via the Integration API's Update customer session endpoint.
  • A per-item effect always indicates what item is being affected wit position and subPosition properties.