# Discount Engine (v1)

## Understanding the Rule builder

The Rule builder is at the heart of the function builder and allows you to build exhaustive logic for your discount function.&#x20;

With the Rule builder You can create rules that determine when discounts are applied to items in a customer's shopping cart. Each line in the cart is checked against these rules. If all conditions are met, the discount is applied.

### **How it Works:**

* You set up conditions in the Rule Builder.
* Each line item in the cart is checked against these conditions.
* If an item satisfies all the conditions, it gets the discount.

{% hint style="info" %}
**Note:** If there are multiple discounts or limit on the lines , the order and way they are applied depend on the Discount Application Strategy and Line limit strategy you have configured.
{% endhint %}

{% hint style="warning" %}
We're moving from Rule engine v1 to v2 for powering more advanced logics and allow merchants to run better promotions than ever before. <br>

Rule engine v1 will continue to remain as a legacy offering by Dollarlabs and maintained - but no new features will be prioritised for it anymore,
{% endhint %}

### Let's understand this with an example ?

**Example:** Let's say you have a discount that applies if all the below conditions are met:

* Condition 1: The cart subtotal must be greater than $100 (Cart sub total > $100).&#x20;
* Condition 2: The customer must be logged in  (Customer logged in =  true).&#x20;
* Condition 3: The product must be from a specific vendor, say "Vendor A" (Product Vendors = Vendor A).

### Let's test our logic on a user's cart

Here's an example cart from a user that we'll test our logic on, assuming that the customer is logged in.&#x20;

* Item 1: Price = $50, Vendor = Vendor A
* Item 2: Price = $60, Vendor = Vendor B
* Item 3: Price = $30, Vendor = Vendor A

Finding 1 → The cart subtotal is $140 (which is greater than $100), and the customer is authenticated.

Finding 2 → The discount is applied to Item 1 and Item 3, but not to Item 2. This way, the rule ensures that only the eligible items get the discount based on the conditions set.&#x20;

***

### Walkthrough of the Rule builder UI

<figure><img src="/files/SNpVuL9xwDcWLkmpeKXs" alt=""><figcaption></figcaption></figure>

1. The `+ OR` button (1 - in the screenshot) allows you to combine multiple conditions, and the discount is applied on the product if **ANY** of the conditions within the condition are satisfied. ([reference](https://shottr.cc/s/1tMS/SCR-20240718-5qj.png))
2. The `+ AND` button (2 - in the screenshot) allows you to combine multiple conditions, and the discount is applied only if **ALL** the conditions satisfied ([reference](https://shottr.cc/s/1MDg/SCR-20240718-5ti.png))
3. The `Add discount` button (3 - in the screenshot) enables you to create multiple discounts, each with its own set of rules that are defined using simple AND, OR logics. ([reference](https://shottr.cc/s/1DTu/SCR-20240718-5va.png))

{% hint style="info" %}
By default, when creating a function, you start with a discount with a single placeholder condition setup.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.dollarlabs.io/dollarlabs-ultimate-discounts/discount-engine-v1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
