Sitecore OrderCloud: Implementing a Buy One, Get One Free Promotion

Maxim Grechuha on February 8, 2025

OrderCloud offers numerous examples of creating various promotions, including the recently added functionality that implements a buy-one, get-one-free promotion.

Each promotion requires two rule expressions: an EligibleExpression, which evaluates the current state of the order and returns true or false, indicating whether the promotion can be applied to it, and a ValueExpression, which assesses the order and returns a monetary value, which is then subtracted from the order subtotal.

The core logic is in the Eligible Expression and Value Expression. Let's use an example from the OrderCloud documentation.

Sitecore OrderCloud Implementing a Buy One, Get One Free Promotion

For our specific example, we will replace 'XYZ' with the identifier of the desired product.

 {
    "LineItemLevel": false,
    "Code": "BOGO_OC_TEST",
    "Name": "BOGO_OC_TEST",
    "Description": "BOGO_OC_TEST",
    "StartDate": "2023-11-28T12:52:00+00:00",
    "ExpirationDate": "2030-12-30T12:52:00+00:00",
    "EligibleExpression": "items.quantity(ProductID = '1234567890') > 1",
    "ValueExpression": "((items.quantity(ProductID='1234567890')/2) - (items.quantity(ProductID='1234567890') % 2 * .5)) * items.total (ProductID='1234567890') / items.quantity(ProductID='1234567890')",
    "CanCombine": true,
    "AllowAllBuyers": true,
    "AutoApply": true,
    "Active": true,
    "UseIntegration": false,
    "Priority": 1
}

Let’s break down each of these expressions separately.

Eligible Expression:

"items.quantity(ProductID = '1234567890') > 1"

This means that the promotion will be applied if the order contains more than one product with the specified identifier.

Value Expression:

 

The expression consists of two main parts.

In the first part of the expression, we calculate the number of products to which the discount should be applied:

"((items.quantity(ProductID='1234567890')/2) - (items.quantity(ProductID='1234567890') % 2 * .5))"

According to the task, every second product should be free.

In the second part, we calculate the cost of a single product:

"items.total (ProductID='1234567890') / items.quantity(ProductID='1234567890')"

Thus, after calculating both parts, we multiply the number of free products by the cost of one product, which ultimately gives us the total discount. Below is an example of how this promotion works in practice.

Sitecore OrderCloud Implementing a Buy One, Get One Free Promotion

One issue with this expression is that the discount is calculated based on the product price without accounting for VAT.

If VAT is fixed and does not change depending on delivery locations or other factors, the second part of the expression can be modified so that the required fixed VAT percentage is added to the price of a single product:

"(items.total (ProductID='1234567890') / items.quantity(ProductID='1234567890')) * 1.15"

This ensures that the discount amount correctly includes VAT.

Sitecore OrderCloud Implementing a Buy One, Get One Free Promotion

However, this method is not suitable if VAT is not a fixed percentage and can vary depending on certain conditions.

There may also be cases where multiple products qualify for the promotion, such as products in a specific category, or other scenarios where the functionality of the Rules Engine is insufficient. In such cases, the recently introduced Promotion Integration feature can be used.