# Buy 3 and pay for 2

> Let's create a BOGO campaign for customers who buy three items from a given list of products or categories of products to get the cheapest one of them for free.

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

Let's imagine our business is a supermarket. We want to give our customers the cheapest pack of
cookies for free every time they purchase three packs out of six types of cookies. They will
get the two cheapest packs of cookies for free if they purchase six, the three cheapest if they purchase
nine, and so on.

To do this, in a [standard campaign](/docs/product/campaigns/overview#standard-campaigns),
let's create:

1. A [cart item filter](/docs/product/rules/cart-item-filters/overview.md)
   to filter items by item category (in our example, cookies).
1. A cart item filter to:
   - Know how many 3-pack groups of cookies are in the cart.
   - Sort eligible items in the cart from cheapest to most expensive.
1. A [promotion rule](/docs/product/rules/overview.md#promotion-rules) to issue the cheapest
   pack of cookies for free for every three packs that the customer buys.

## Filter the cart items by item category

Let's filter the cart by **item category** to find all the packs of cookies that
belong to the eligible type. This allows us to use
this information to create more filters.

**Filter items by conditions**:

- Attribute is <Attribute name="Item category (Item)" type="builtin" />.

  :::tip
  Alternatively, select <Attribute name="SKU of item (Item)" type="builtin" />
  or any other item attribute that suits your campaign needs.
  :::
- **Is one of** `cookies1`, `cookies2`, `cookies3`, `cookies4`, `cookies5` and `cookies6`.
- **Save as** <Attribute name="filter_items" type="filter" />.

To the right of the filter name, you can see the type of this filter is **list of Cart Items**.
This means that the filter will be available wherever other lists,
such as the list of cart items, are available.

## Sort and group eligible items

Let's create a second cart item filter to do the following:
- Sort the eligible items in ascending order of their price.

  This gives us the list of items to discount by priority
  so we can discount the cheapest items in the cart.
- Divide all eligible packs of cookies in the cart by 3.

  This tells us how many free items a customer can get in the same session.

:::note
This doesn't select the cheapest items in each trio of items, but merely the cheapest items
amongst the items eligible for a discount, regardless of grouping.
:::

- **Start with this list of cart items** is <Attribute name="filter_items" type="filter" />.
- **Add Filter Step**: **Sort items by attribute**.
  - **Sort by**: <Attribute name="Price of item (Item)" type="builtin" />, where price is **Ascending**.
- **Add Filter Step**: **Select the first No. of items**:
  - Cart item filter is <Attribute name="filter_items item count" type="filter" />.
  - Formula is `ROUND_DOWN(`<Attribute name="filter_items item count" type="filter" />`)/3`.
    :::tip
    - Insert the cart item filter using the [Attribute Selector][Attribute Selector],
      then select the text  <Attribute name="[Bindings.filter_items.Count]" type="filter" />
      to display the rounding options.
    - In the text field, you can type `/3` after the filter name.
    :::
- **Save as** <Attribute name="groups_of_3_with_cheapest_item_first" type="filter" />.

The filter type is **list of Cart items**.

## Give the cheapest item for free for every three items the customer buys

Let's [build a promotion rule](/docs/product/rules/create-and-manage-rules.md#create-a-promotion-rule)
to apply our BOGO offer. When a customer purchases three packs of cookies, they will see a 100%
discount applied to the cheapest of them.

Let's name the rule `3x2 offer`. It has one condition and one effect.

:::tip
You can add more conditions that suit your campaign needs.
:::

### Condition

**Check attribute value:**

- Cart item filter is <Attribute name="filter_items item count" type="filter" />.
- **Is greater than or equal to** `1`.

### Effect

**Discount individual items**:

- **List of items** is <Attribute name="groups_of_3_with_cheapest_item_first" type="filter" />.
- **Discount name** is `3rd item 100% off`.
- **Discount value** is <Attribute name="Price of item" type="builtin" />`*100%`.

## Related pages

- [Create and manage rules](/docs/product/rules/create-and-manage-rules.md)
- [Create and manage item bundles](/docs/product/rules/create-and-manage-bundles.md)
- [Attribute selector][Attribute Selector]

[Attribute Selector]: /docs/product/rules/overview.md#attribute-selector
