Skip to main content

Discounting a session based on purchase location

Let's create a customer session custom attribute referring to the customer's shipping city and use it in a promotion rule to discount the session total.

Storing the shipping city

Let's start by storing the customer's shipping city so we can use it in the Rule Builder. To do this, we create a custom attribute.

  • Associated entity: customer session
  • Attribute type: string
  • API name: ShippingCity
  • Rule Builder name: Shipping city
  • Rule Builder description: Customer session shipping city
  • Picklist values: Berlin, Paris, London, Madrid, Helsinki, Dublin and Lisbon
  • Available in our Application

Setting the value of the attribute

The attribute is ready to be used by the integration layer. Since we have created a customer session attribute, its value is set programmatically using the customer session endpoint.

For example, we can set ShippingCity to Berlin with the following payload:

{
"customerSession": {
"profileId": "DE29HDG94NV",
"state": "open",
"cartItems": [
{
"name": "Camera",
"sku": 483092756,
"quantity": 2,
"price": 159.99
}
],
"attributes": {
"ShippingCity": "Berlin"
}
},
"responseContent": [
"customerSession",
"customerProfile"
]
}

Issuing a discount on the session total

Let's build the rule for customers who choose Berlin as their shipping city to receive a discount. We can name it Discount on session total when shipping to Berlin, and it has 1 condition and 1 effect.

Condition

Validate attribute value:

  • Attribute is Shipping city (current session).
  • Is equal to Berlin.

Effect

Discount session total: Name is Berlin 10% off and Discount value is [Session.Total]*10%.