# Discount bundles

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Let's create a [promotion rule](/docs/product/rules/overview.md#promotion-rules) that awards customers with a $50 pro-rata discount per bundle of one bike and two helmets found in their sessions.

## Create the promotion

### Cart item filters

Let's start by creating the [cart item filters](/docs/product/rules/cart-item-filters/overview.md).
We need them to identify helmets and bikes. Then we'll create a bundle based on these items.
We've already used cart item filters to check the category of cart items in the
[Different discounts for different categories tutorial](/docs/product/tutorials/sample-campaigns/discount-categories.md).

To create the cart item filter:

1. In the [Rule Builder](/docs/product/rules/overview.md) of the [campaign](/docs/product/campaigns/overview.md),
   click <Filter className="icon" /> **Cart Item Filters**.
1. Click **Add Filter**.
1. Click **Add Filter Step** and select **Filter items by conditions**.
1. Set the filter to <Attribute name="Item category (Item)" type="builtin" /> **is equal to** `Road Bikes`.
1. In **Save As**, type `RoadBikes` and click **Save Filter**.

   This cart item filter returns a **list of cart items**.

Repeat the same steps to create a filter to find items in the `Helmets` category and count them.

### Create the bundle definition

To bundle the items, let's create a [bundle definition](/docs/product/rules/create-and-manage-bundles.md):

1. Click **Bundle Definitions** > **Add Bundle Definition**.
1. In **Name**, type `1RoadBike2Helmets`.
1. In **List of cart items**, select **RoadBikes** and choose **1** item.
1. Click **Add list**.
1. In **List of cart items**, select **Helmets** and choose **2** item.

We have a bundle definition composed of one item from our `RoadBikes` cart item filter,
and two items from the `Helmets` cart item filter. The bundle definition will create as
many bundles as possible from the current state of the cart.

We know how many bundles are created thanks to the <Attribute name="Count (1RoadBike2Helmets)" type="filter" /> attribute.
This attribute is created automatically with the bundle definition.

### Rule

Let's create the rule to trigger the discount:

- Condition: **Check attribute value** and compose the following
  expression: <Attribute name="Count (1RoadBike2Helmets)" type="filter" />`is greater than or equal to 1`

  This check that our bundle definition managed to create a least one bundle.

- Effect: **Discount bundles pro rata** and select:

  - **Bundle definition**: `1RoadBike2Helmets`
  - **Discount Name**: `$50 off a bundle of items`
  - **Discount value for each bundle**: `50`

## Run the campaign

To run the campaign, we send a suitable session to the Integration API's [Update customer session][cs] endpoint.

<Tabs
  defaultValue="req"
  values={[
    {label: '🚀 Request', value: 'req'},
    {label: '✅ Response', value: 'res'},
  ]}>

<TabItem value="req">

The session contains two helmets and one road bike, which is the bundle definition.

```json title="Sending a session update" {12,22,32} showLineNumbers
CURL -X PUT https://mycompany.europe-west1.talon.one/v2/customer_sessions/my_session_id -d
'{
  "customerSession": {
    "profileId": "{{integrationId}}",
    "state": "closed",
    "cartItems": [
      {
        "name": "ProductC",
        "sku": "sku-00004",
        "quantity": 2,
        "price": 200,
        "Category": "Road Bikes",
        "weight": 0,
        "position": 0,
        "attributes": {}
      },
      {
        "name": "ProductD",
        "sku": "sku-00005",
        "quantity": 1,
        "price": 49.99,
        "Category": "Helmets",
        "weight": 0,
        "position": 0,
        "attributes": {}
      },
      {
        "name": "ProductE",
        "sku": "sku-00006",
        "quantity": 1,
        "price": 39.99,
        "Category": "Helmets",
        "weight": 0,
        "position": 0,
        "attributes": {}
      }
    ],
    "couponCodes": [
      ""
    ],
    "referralCode": "",
    "attributes": {},
    "additionalCosts": {}
  },
  "responseContent": []
}'
```

</TabItem>
<TabItem value="res">

We receive this response, which shows the `setDiscountPerItem` effect for _each item_.

As we saw in the [Different discounts for different categories tutorial](/docs/product/tutorials/sample-campaigns/discount-categories.md),
the `position` property represents which item is impacted by the effect based
on the item's position in the `cartItems` array sent in the update request.

```json title="Response" {15,16,33,34,51,52} showLineNumbers
{
    "createdCoupons": [],
    "createdReferrals": [],
    "effects": [
        {
            "campaignId": 9986,
            "rulesetId": 41128,
            "ruleIndex": 0,
            "ruleName": "$50 on Bundle: 1 Road Bike & 2 Helmets",
            "effectType": "setDiscountPerItem",
            "evaluationGroupID": 38,
            "evaluationGroupMode": "stackable",
            "props": {
                "name": "$50 off a bundle of items#0",
                "value": 34.49,
                "position": 0,
                "subPosition": 0,
                "totalDiscount": 50,
                "bundleIndex": 0,
                "bundleName": "1bike2helmets"
            }
        },
        {
            "campaignId": 9986,
            "rulesetId": 41128,
            "ruleIndex": 0,
            "ruleName": "$50 on Bundle: 1 Road Bike & 2 Helmets",
            "effectType": "setDiscountPerItem",
            "evaluationGroupID": 38,
            "evaluationGroupMode": "stackable",
            "props": {
                "name": "$50 off a bundle of items#1",
                "value": 8.62,
                "position": 1,
                "subPosition": 0,
                "totalDiscount": 50,
                "bundleIndex": 0,
                "bundleName": "1bike2helmets"
            }
        },
        {
            "campaignId": 9986,
            "rulesetId": 41128,
            "ruleIndex": 0,
            "ruleName": "$50 on Bundle: 1 Road Bike & 2 Helmets",
            "effectType": "setDiscountPerItem",
            "evaluationGroupID": 38,
            "evaluationGroupMode": "stackable",
            "props": {
                "name": "$50 off a bundle of items#2",
                "value": 6.89,
                "position": 2,
                "subPosition": 0,
                "totalDiscount": 50,
                "bundleIndex": 0,
                "bundleName": "1bike2helmets"
            }
        }
    ]
}
```

</TabItem>
</Tabs>

:::tip Key Takeaways
- You can bundle items with a cart item filter or use the [bundle feature](/docs/product/rules/create-and-manage-bundles.md).
:::

## Related pages

- [Use conditions](/docs/product/rules/conditions/overview.md) and [effects](/docs/product/rules/effects/overview.md)
- [Create and manage item bundles](/docs/product/rules/create-and-manage-bundles.md)
- [Cart item filters](/docs/product/rules/cart-item-filters/overview.md)
- [Application cart item filters](/docs/product/applications/manage-application-cart-item-filters.md)
- [setDiscountPerItem effect](/docs/dev/integration-api/api-effects.md#setdiscountperitem)

[cs]: /integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2
