Different discounts for different categories
Prerequisites
- Create your Integration API key.
- If you haven't done so already, fork our Sample Campaigns collection in Postman:
- In the Campaign Manager, open the EASY-DISCOUNT: Specific discounts on categories demo campaign and click Activate Campaign.
- 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:
- Click Add Filter.
- Click Add Filter Step and select Filter items by condition.
- Set the filter to Item category (Item) is equal to
Road Bikes
. - 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
- Name the rule
10% off Category Helmets
. - 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:
- Set the List of items to
Helmets
. - Set the Discount name to
10% off helmets
. - 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:
- Select the RoadBikes item count (RoadBikes) for the condition.
- Select RoadBikes in the effect.
- 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:
- 🚀 Request
- ✅ Response
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.
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": []
}'
We receive this response, which shows the setDiscountPerItem
effect for each item.
- Lines: 14, 27, and 40: The
position
property represents which item is impacted by the effect based on the item's position in thecartItems
array sent in the update request. - Lines 28 and 41: The
subPosition
property represents which unit of the given item is impacted in the effect. This only relevant whenquantity
is greater than 1 in the session, like for our helmets.
{
"createdCoupons": [],
"createdReferrals": [],
"effects": [
{
"campaignId": 250,
"rulesetId": 502,
"ruleIndex": 0,
"ruleName": "10% off Category Helmets",
"effectType": "setDiscountPerItem",
"props": {
"name": "10% off helmets#1",
"value": 3.0,
"position": 1,
"subPosition": 0
}
},
{
"campaignId": 250,
"rulesetId": 502,
"ruleIndex": 0,
"ruleName": "10% off Category Helmets",
"effectType": "setDiscountPerItem",
"props": {
"name": "10% off helmets#1",
"value": 3.0,
"position": 1,
"subPosition": 1
}
},
{
"campaignId": 250,
"rulesetId": 502,
"ruleIndex": 1,
"ruleName": "40% off Category Road Bikes",
"effectType": "setDiscountPerItem",
"props": {
"name": "40% off per item#0",
"value": 80.0,
"position": 0,
"subPosition": 0
}
}
]
}
- 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
andsubPosition
properties.