# B2B Setup

### <mark style="color:red;">1. Add the B2B App to the Relevant Project in ACC</mark>

In **B2B Dynamic Settings**, add a `password` field in the `Shop` configuration:

```json
SHOP={
    "key": "SHOP",
    "value": {
        "url": "{{SHOP_URL}}",
        "shipping_option_slug": "b2b",
        "payment_option_slug": "b2b"
        ...
        "password": "B2B123456", // field to be added
    }
}
```

### <mark style="color:red;">2. Set Environment Value on the Shop Side</mark>

Ensure that the `password` fields match on both sides:

```
B2B_EXTENSION_CONF={"api_url": "https://{B2B_APP_DOMAIN}/api/v1/", "password": "B2B123456"}
```

### <mark style="color:red;">3. Define the Model Schema for User Model on the Shop Side</mark>

Enter this configuration via **COMMERCE API** as it will not reflect on forms within Omnitron screens:

```json
{
  "b2b_token": {
    "key": "b2b_token",
    "label": "B2B Token",
    "data_type": "text"
  },
  "division_erp_code": {
    "key": "division_erp_code",
    "label": "B2B Division ERP Code",
    "data_type": "text"
  }
}
```

### <mark style="color:red;">4. Integrate PromotionGateway for B2B Discounts on the Shop Side</mark>

Set the `offer_priority` to the highest among existing campaigns.

```json
{
  "conf": {
    "klass": "omnishop.promotions.backend.b2b.service.B2BPromotionService",
    "offer_priority": 9999
  },
  "gateway": "b2b",
  "id": 1,
  "is_active": true,
  "name": "b2b"
}
```

### <mark style="color:red;">5. Add a ShippingOption for B2B on the Shop Side</mark>

Ensure the `slug` in the created ShippingOption matches the `shipping_option_slug` in Step 1.

```json
{
  "calculator": {
    "name": "Free Calculator",
    "slug": "free-calculator"
  },
  "delivery_type": "standard",
  "description": null,
  "id": 6,
  "is_active": true,
  "kwargs": {},
  "name": "B2B",
  "rule": {
    "name": "Client Type Rule",
    "slug": "client-type-rule",
    "clients": [
      "b2b"
    ]
  },
  "slug": "b2b"
}
```

### <mark style="color:red;">6. Add a CargoCompany for B2B in Omnitron</mark>

```json
{
    "pk": 67,
    "name": "b2b",
    "erp_code": "b2b",
    "shipping_company": "other",
    "modified_date": "2023-09-01T09:41:10.288813Z",
    "created_date": "2023-09-01T09:41:10.288781Z"
}
```

### <mark style="color:red;">7. Configure PaymentOption for B2B on the Shop Side</mark>

Ensure the `slug` matches the `payment_option_slug` defined in Step 1.

```json
{
  "config": {
    "rule": {
      "klass": "omnishop.payments.rules.B2BPaymentRule",
      "params": {}
    }
  },
  "is_active": true,
  "name": "B2B",
  "payment_type": "b2b",
  "slug": "b2b"
}
```
