> For the complete documentation index, see [llms.txt](https://docs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akinon.com/tutorials/b2b/how-to-set-up-division-specific-prices-and-order-types-in-b2b.md).

# How to Set Up Division-Specific Prices and Order Types in B2B

Many brands give each dealer its own prices, and sell under more than one order type, for example cash and carry from the current stock and pre-orders from the showroom collection, each with its own stock. This guide sets up segments so that each division sees its own prices, and its users switch between order types, each with its own B2B basket.

## <mark style="color:red;">How It Works</mark> <a href="#how-it-works" id="how-it-works"></a>

The setup uses three building blocks in Commerce:

* **A customer group for each division.** The group holds the users of the division.
* **A segment for each division and order type.** The segment combines the price list of the division with the stock list of the order type.
* **Segment rules.** A segment applies when the user belongs to the group of the division and has selected the segment as the order type. The user can select only the segments of their own division.

B2B keeps a separate basket for each segment, so the baskets of the order types don't mix. A quotation keeps the segment of its basket, and B2B creates its orders in that segment, with its prices and stock.

This guide uses the following example:

| Segment                     | Customer group | Price list       | Stock list           |
| --------------------------- | -------------- | ---------------- | -------------------- |
| Division A / Cash and Carry | Division A     | Division A Price | Cash and Carry Stock |
| Division A / Showroom       | Division A     | Division A Price | Showroom Stock       |
| Division B / Cash and Carry | Division B     | Division B Price | Cash and Carry Stock |
| Division B / Showroom       | Division B     | Division B Price | Showroom Stock       |

## <mark style="color:red;">Before You Begin</mark> <a href="#before-you-begin" id="before-you-begin"></a>

Make sure that you have the following:

* A working B2B setup. If you haven't set up B2B yet, follow [how to set up B2B from scratch](https://docs.akinon.com/tutorials/b2b/how-to-set-up-b2b-from-scratch.md).
* A storefront that lets B2B users choose the order type. It lists the segments that the user can select with `GET /users/segments/`, and selects one with `POST /users/segments/{id}/set/`. Until the user selects an order type, none of these segments applies, and the user sees the default price and stock lists of the catalog.
* An Omnitron user who can manage price lists, stock lists, catalogs and customer groups.

## <mark style="color:red;">Set Up the Segments</mark> <a href="#set-up-the-segments" id="set-up-the-segments"></a>

{% stepper %}
{% step %}

### Create the price and stock lists

1. Create a price list for each division, and a stock list for each order type, in **Products and Catalogs > Price Lists** and **Products and Catalogs > Stock Lists**. For every list, set **ERP Connection** to **Yes** and enter an **ERP Code**: Commerce receives only lists with a code, and a segment can only use lists that Commerce has received.
2. Add the lists to the catalog of the sales channel as extra lists, in **Products and Catalogs > Catalogs**.

Both steps work the same way as for assortment packs. For the details, see the price list, stock list and catalog steps in [how to sell assortment packs in B2B](https://docs.akinon.com/tutorials/b2b/how-to-sell-assortment-packs-in-b2b.md).
{% endstep %}

{% step %}

### Create a customer group for each division

1. In Omnitron, go to **Sales Channels > Sales Channel Settings > Customer Groups** and open **Customer Groups**.
2. Click **New Customer Group**, and create a group for each division, for example `Division A`. Use a name that identifies the division, such as its name and ERP code.

   <figure><img src="https://3333414532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbwGN7KwvYi0iLbjtnXz%2Fuploads%2Fgit-blob-ea478c4f7680e0018ded012d85882ba4fbe6b417%2Fb2b-division-customer-group.png?alt=media" alt="The new customer group form with the name Division A"><figcaption></figcaption></figure>
3. Open the group, and add the users of the division with their **+** icon. To add several users at once, select them and use **Select Action > Add Selected Users**. The members of the group appear on the right.

   <figure><img src="https://3333414532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbwGN7KwvYi0iLbjtnXz%2Fuploads%2Fgit-blob-d1807eb0efd56926f62efc89c7e490f3f70dc48e%2Fb2b-division-customer-group-users.png?alt=media" alt="The Division A customer group with its member, next to the list of all users"><figcaption></figcaption></figure>

{% hint style="warning" %}
B2B doesn't add users to customer groups. When you create a division user, also add them to the group of their division. To avoid this, use the ERP code of the division in the rules instead, as described in [using the division's ERP code](#use-the-divisions-erp-code-instead-of-a-customer-group).
{% endhint %}
{% endstep %}

{% step %}

### Create a segment for each division and order type

1. In Omnitron, go to **Sales Channels > Sales Channel Settings > Customer Groups** and open **Customer Groups Settings**.
2. Click **New Customer Groups Setting**, enter the following values for each division and order type, and then click **SAVE**:

   | Field                             | Value                                                                                                                                                                  |
   | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   | Customer Groups Settings Name     | The division and the order type, for example `Division A / Cash and Carry`.                                                                                            |
   | Customer Groups Settings Slug     | A unique slug, for example `division-a-cash-and-carry`. The rule below refers to it.                                                                                   |
   | Customer Groups Settings Config   | The segment rule. See the example below.                                                                                                                               |
   | Availability Configuration        | The availability rule. See the example below.                                                                                                                          |
   | Customer Groups Settings Priority | A unique number. Segments are checked from the smallest priority number up, and the first matching one applies. A segment that the user has selected is checked first. |
   | Customer Groups Settings Status   | Active                                                                                                                                                                 |
   | Stock List                        | The stock list of the order type, for example `Cash and Carry Stock`.                                                                                                  |
   | Price List                        | The price list of the division, for example `Division A Price`.                                                                                                        |
   | Validity Date                     | Optional. The period in which the segment can be selected, for example a showroom season.                                                                              |

   <figure><img src="https://3333414532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbwGN7KwvYi0iLbjtnXz%2Fuploads%2Fgit-blob-eb6943ed88a698af7430be6218ee53516959642e%2Fb2b-division-segment.png?alt=media" alt="The Division A / Cash and Carry segment with its rules, priority, stock list and price list"><figcaption></figcaption></figure>

The **segment rule** applies the segment when the user belongs to the group of the division and has selected this segment:

```json
{
  "rule": "and",
  "params": {
    "children": [
      {"rule": "group", "params": {"name": "Division A"}},
      {"rule": "liquer", "params": {"query": "request__session__SELECTED_SEGMENT_SLUG", "value": "division-a-cash-and-carry"}}
    ]
  }
}
```

The **availability rule** lets every user of the division select the segment:

```json
{"rule": "group", "params": {"name": "Division A"}}
```

Use the same availability rule for all segments of a division. When all segments are created, the list shows one segment for each division and order type:

<figure><img src="https://3333414532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbwGN7KwvYi0iLbjtnXz%2Fuploads%2Fgit-blob-2a57d8e526b4bd0caa3b25418ef11a58153e296e%2Fb2b-division-segments.png?alt=media" alt="Four segments for two divisions and two order types, with their price and stock lists"><figcaption></figcaption></figure>

For the rule types, see **Technical Guides > Commerce > User Segmentation & Rules**.

{% hint style="warning" %}
The group name in both rules must match the name of an existing customer group exactly. If it doesn't, users can't select the segment, or the segment never applies after they select it.
{% endhint %}

{% hint style="warning" %}
The availability rule must include every user who orders in the segment. B2B selects the segment of the quotation in Commerce while it creates the order, and Commerce rejects a segment that the user can't select, so the order fails. The same happens when the validity date of the segment has ended before the quotation is approved.
{% endhint %}

{% hint style="info" %}
After a segment is selected, Commerce checks its rule again on every request. If the quotation owner no longer matches it, for example after leaving the customer group, the default price and stock lists apply, and the order is likely to fail with `UnpaidAmountCheck`.
{% endhint %}
{% endstep %}

{% step %}

### Check the result

1. Sign in to the storefront as a user of Division A, and select **Cash and Carry** as the order type. The products show the prices of Division A and the cash and carry stock.
2. Add a product to the B2B basket, and then switch to **Showroom**. The showroom stock applies, and the basket is empty: each order type has its own basket.
3. Sign in as a user of Division B. Only the segments of Division B can be selected, with the prices of Division B.
   {% endstep %}
   {% endstepper %}

## <mark style="color:red;">Use the Division's ERP Code Instead of a Customer Group</mark> <a href="#use-the-divisions-erp-code-instead-of-a-customer-group" id="use-the-divisions-erp-code-instead-of-a-customer-group"></a>

B2B saves the ERP code of the division on every Commerce user that it creates. Rules that check this code match new division users automatically, so you don't need to maintain customer groups:

* Segment rule:

  ```json
  {
    "rule": "and",
    "params": {
      "children": [
        {"rule": "liquer", "params": {"query": "user__attributes__division_erp_code__in", "value": ["DIV-A", "DIV-A-01"]}},
        {"rule": "liquer", "params": {"query": "request__session__SELECTED_SEGMENT_SLUG", "value": "division-a-cash-and-carry"}}
      ]
    }
  }
  ```
* Availability rule:

  ```json
  {"rule": "liquer", "params": {"query": "user__attributes__division_erp_code__in", "value": ["DIV-A", "DIV-A-01"]}}
  ```

Main divisions and their sub-divisions have different ERP codes. List the ERP codes of every division that shares the prices, as in the example above.

B2B writes the ERP code to a user when the user is created or saved. If you change the ERP code of a division, save its users again in Omnitron, and update the rules.

## <mark style="color:red;">Troubleshooting</mark> <a href="#troubleshooting" id="troubleshooting"></a>

| Symptom                                                          | Cause                                                                                                                                  | Solution                                                                                         |
| ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| A user sees the default prices instead of the division prices.   | The user hasn't selected an order type yet, or isn't in the group of the division.                                                     | Select an order type on the storefront, and check **Create a customer group for each division**. |
| A user can't select an order type.                               | The availability rule doesn't match the user.                                                                                          | Add the user to the group of the division, or check the ERP codes in the rule.                   |
| A user selects an order type, but still sees the default prices. | The group name in the segment rule doesn't match an existing customer group, for example because the order type was added to the name. | Use the exact customer group name in both rules.                                                 |
| A new division user sees the default prices.                     | The user wasn't added to the customer group.                                                                                           | Add the user to the group, or use the ERP code rules.                                            |
| Orders fail after approval.                                      | The availability rule of the quotation's segment doesn't match the quotation owner, or the validity date of the segment has ended.     | Check the availability rule and the validity date of the segment.                                |
| A price or stock list doesn't appear in the segment form.        | The list has no code, or it hasn't reached Commerce yet.                                                                               | Enter an ERP code for the list, add it to the catalog, and wait for the sync.                    |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.akinon.com/tutorials/b2b/how-to-set-up-division-specific-prices-and-order-types-in-b2b.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
