> 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/commerce/how-to-configure-remote-attribute-based-shipping.md).

# How to Configure Remote Attribute Based Shipping

This document provides a step-by-step guide on how to configure **Remote Attribute Based Shipping Options** in Commerce. This flow lets an external service decide how the quantities of each basket line are split into **delivery groups** at checkout (for example `express`, `standart`, `global`), while Commerce presents a separate, selectable shipping option for each group.

It is useful when grouping cannot be expressed by a static product attribute — most commonly when the **same SKU** must be fulfilled partly from a store (`express`) and partly from a warehouse (`standart`), including **partial** splits (e.g. of 7 units, 4 ship express and 3 standart).

## <mark style="color:red;">1. Overview</mark> <a href="#id-1-overview" id="id-1-overview"></a>

When the customer reaches the shipping step, Commerce calls the configured remote service with the current basket and shipping address. The service responds with a list of **groups**; each group has a label (`attributeValue`) and an **allocation** describing how many units of each basket item belong to it. Commerce then shows one group per label, each with its own shipping options and fee, and lets the customer choose within every group.

Key characteristics:

* **Dynamic groups:** the number of groups is not fixed — Commerce uses exactly the groups the service returns.
* **Basket is never mutated:** the split is ephemeral; it is materialized into separate shipping groups only when the order is placed.
* **Per-group options and fees:** each group is bound to its own shipping option(s) and price.
* **Non-blocking:** if the service is unreachable, times out, or returns an invalid body, Commerce falls back to a single group so checkout is not interrupted.

The request/response contract of the remote service is documented in [Remote Attribute Based Shipping Flows](https://github.com/akinon/docs/tree/main/apireference/flows/remote-attribute-based-shipping-flows.md).

## <mark style="color:red;">2. How groups connect to shipping options</mark> <a href="#id-2-how-groups-connect" id="id-2-how-groups-connect"></a>

This is the part that ties everything together. The remote service only returns **group labels** (`express`, `standart`, `global`, …) — it does **not** return any shipping company or price. The mapping from a group label to the shipping options shown for it lives entirely in Omnitron and is expressed with a single rule: the **Attribute Based Shipping Group Rule**.

For every group label the service can return, you create one (or more) **Attribute Based Shipping Option** records whose **Rule** is:

```json
{
  "name": "Attribute Based Shipping Group Rule",
  "slug": "attribute-based-shipping-group-rule",
  "group_value": "express"
}
```

At checkout, for each group the service returns, Commerce evaluates the active Attribute Based Shipping Options and offers an option in that group **only if** its group rule's `group_value` equals the group's label. In other words:

> The link between the remote value (`express` / `standart` / `global`) and attribute-based shipping is the `group_value` field of the **Attribute Based Shipping Group Rule** — it must match the label the service returns, character for character.

A few consequences:

* **One option per group** → one Attribute Based Shipping Option per label (each with its own calculator/fee).
* **Several choices in a group** → several Attribute Based Shipping Options that share the same `group_value`.
* **An option for every group** → give that option an **Any Rule** instead of a group rule; it will appear in all groups.
* No product attribute is involved — unlike the standard attribute-based flow, the value is supplied by the remote service at runtime, not read from the product.

## <mark style="color:red;">3. Setup</mark> <a href="#id-3-setup" id="id-3-setup"></a>

### <mark style="color:red;">3.1. Enable the checkout page</mark>

Navigate to **Sales Channels → Sales Channel Settings → Dynamic Settings**, find `CHECKOUT_SHIPPING_OPTION_SELECTION_PAGE`, and set its value to:

```
RemoteAttributeBasedShippingOptionSelectionPage
```

Only one shipping option selection page can be active at a time.

### <mark style="color:red;">3.2. Configure the remote provider</mark>

In the same Dynamic Settings screen, set `REMOTE_ATTRIBUTE_BASED_SHIPPING_OPTION_PROVIDER` with the provider class and the service credentials (URL, username, password) shared during integration:

```json
{
    "klass": "omnishop.shippings.remote_attribute_based_shipping_options.providers.ExtensionAttributeBasedShippingOptionProvider",
    "conf": {
        "base_url": "https://<your-extension-host>",
        "username": "<username>",
        "password": "<password>"
    }
}
```

| Field           | Description                                                                                        |
| --------------- | -------------------------------------------------------------------------------------------------- |
| `klass`         | Provider implementation. Use the extension provider shown above.                                   |
| `conf.base_url` | Base URL of the remote service (Commerce calls `POST {base_url}/attribute-based-shipping-groups`). |
| `conf.username` | Username for HTTP Basic authentication.                                                            |
| `conf.password` | Password for HTTP Basic authentication.                                                            |

### <mark style="color:red;">3.3. Define the shipping options (carriers)</mark>

Under **Sales Channels → Sales Channel Settings → Shipping Options**, create the carriers you will offer, one per choice you want the customer to see — for example `Express Kargo`, `Standart Kargo`, `Global Kargo`. Note each carrier's **slug**; you will need it in Step 3.5 for group surcharges. At this stage the Calculator and Rule on the shipping option itself are not important — the ones that matter are set on the Attribute Based Shipping Option in the next step.

### <mark style="color:red;">3.4. Bind each group to its shipping options</mark>

Navigate to **Sales Channels → Sales Channel Settings → Attribute Based Shipping Options** and click **+ New Attribute Based Shipping Option**. For each group label the remote service returns, add a record:

1. **Shipping Option:** the carrier from Step 3.3 to offer for this group.
2. **Calculator:** the fee for this group, e.g. a fixed price:

   ```json
   { "name": "Fixed Price Calculator", "slug": "fixed-price-calculator", "fixed_price": "19.90" }
   ```
3. **Rule:** the **Attribute Based Shipping Group Rule** with `group_value` set to the group label:

   ```json
   { "name": "Attribute Based Shipping Group Rule", "slug": "attribute-based-shipping-group-rule", "group_value": "express" }
   ```
4. Set the status to **active** and save. Repeat for every group label, and add extra records for a label if you want more than one choice in that group.

### <mark style="color:red;">3.5. (Optional) Add a surcharge to a group</mark>

To add a fee to a specific group — for example an import fee on `global` — do **not** set anything on the shipping option itself. Instead add an entry to the `EXTRA_FEE_CONFIGURATIONS` dynamic setting of type `shipping_option`, bound to that group's carrier **slug**. The fee amount is the price of the referenced fee product (`sku`); `per_item` controls whether it is charged per unit or once:

```json
{
    "global_import_fee": {
        "type": "shipping_option",
        "sku": "GLOBAL-IMPORT-FEE",
        "is_active": true,
        "kwargs": { "shipping_option_slug": "global-kargo", "per_item": true }
    }
}
```

## <mark style="color:red;">4. Worked example</mark> <a href="#id-4-worked-example" id="id-4-worked-example"></a>

Suppose the remote service can return three groups. You configure three Attribute Based Shipping Options (Step 3.4):

| Group label (`group_value`) | Shipping Option | Calculator (fee) |
| --------------------------- | --------------- | ---------------- |
| `express`                   | Express Kargo   | 19.90            |
| `standart`                  | Standart Kargo  | 29.90            |
| `global`                    | Global Kargo    | 49.90            |

A customer adds 7 units of a product whose stock is split 4 (store) / 3 (warehouse). At checkout Commerce calls the remote service, which returns:

```json
{
  "groups": [
    { "attributeValue": "express",  "allocation": [ { "basketItemPk": 30928, "quantity": 4 } ] },
    { "attributeValue": "standart", "allocation": [ { "basketItemPk": 30928, "quantity": 3 } ] }
  ]
}
```

Commerce then presents two groups: **express** (4 units → Express Kargo, 19.90) and **standart** (3 units → Standart Kargo, 29.90). If the basket also contained a global product, a third **global** group (→ Global Kargo, 49.90 + the import fee from Step 3.5) would appear. The customer selects one option per group and continues; when the order is placed, each group becomes its own shipping group and the line's 7 units are materialized as 4 + 3 order items accordingly.

## <mark style="color:red;">5. Verify</mark> <a href="#id-5-verify" id="id-5-verify"></a>

Send a request to the checkout shipping step and confirm the groups appear:

```
POST /orders/checkout/?page=RemoteAttributeBasedShippingOptionSelectionPage
```

The `page_context.attribute_based_shipping_options` object contains one entry per group label, each listing its shipping options, the group's `product_ids`, and its `allocation` — a list of `{ "basket_item_id": <id>, "quantity": <n> }` showing how many units of each basket item belong to that group. Select one option per group by posting a JSON map of `group label → shipping option id`:

```
attribute_based_shipping_options={"express": 4, "standart": 5}
```

After the order is created, verify that its order items are distributed across the expected shipping groups (one `ShippingOptionGroup` per group, with its amount).

## <mark style="color:red;">6. Notes and limitations</mark> <a href="#id-6-notes" id="id-6-notes"></a>

* The `group_value` in each Attribute Based Shipping Group Rule must exactly match a label the remote service returns; otherwise that group will have no options.
* Bundle (parent/child) and mergeable/unit-addable lines are not split; they are kept whole in a single group.
* Cash on delivery (COD) needs extra configuration because a basket can use a different shipping option in each group. To offer COD only when the whole basket uses a single shipping option (for example only `express` or only `standard`), add `SingleShippingOptionRule` to the COD payment option, with the shipping option slugs in `slugs`. The remote service must return those slugs as its group labels. To turn COD off for this flow instead, use `ShippingOptionPageRule`. See [Cash on Delivery (COD)](https://github.com/akinon/docs/tree/main/technicalguides/commerce/attribute-based-shipping-options.md#cash-on-delivery-cod).

## <mark style="color:red;">7. FAQ</mark> <a href="#id-7-faq" id="id-7-faq"></a>

**Does every basket item have to be placed in a group? What about an item that belongs to no group (e.g. a gift card)?**

No — you do not have to assign every item to a group. Any item you do not include in the allocation (or an item whose split is inconsistent) is placed **whole, at its full quantity, into a fallback group whose label is `None`**. So you can simply leave a gift card out of the allocation and it will land in the `None` group on its own. The only requirement is that the `None` group has a shipping option too: create an Attribute Based Shipping Option whose Group Rule `group_value` is `None` (or give one option an **Any Rule** so it appears in every group). Otherwise the `None` group is shown with no options and checkout cannot proceed for it.

**A line has quantity 4. The service allocates 1 to `express` and 2 to `standart`, and 1 unit is not found anywhere (sum = 3 ≠ 4). What does Commerce do — does it drop the missing unit and reduce the line to 3?**

No, the quantity is never reduced. When a line's allocation does not sum exactly to its quantity, the split is treated as **inconsistent and discarded entirely**: the whole line — all 4 units — is kept together and placed in the single `None` fallback group. The `express`/`standart` split for that line is not applied. In short, either the allocation sums exactly to the line quantity (then it is split), or the line is not split at all and stays whole in the `None` group. There is no "drop the missing unit" behavior.

**Is the `segment.name` field in the request JSON `null` or the string `"null"` when there is no active segment?**

JSON `null`. When there is no active segment, `segment.name` is sent as a JSON `null`, not the string `"null"`.

**Are the resulting shipping groups saved on the order automatically, or does the integration have to persist anything?**

They are saved automatically. When the order is placed, Commerce creates one `ShippingOptionGroup` per group and assigns each order item to its group; the basket is not mutated beforehand. The integration does not persist anything on Commerce's side — it only has to return the allocation from the `POST {base_url}/attribute-based-shipping-groups` endpoint.


---

# 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/commerce/how-to-configure-remote-attribute-based-shipping.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.
