# Fulfillment

Fulfillment is handled under four items. These are shipping options, shipping company, tracking number and invoice number.

## Shipping Options

**Methods**: `GET`, `POST`, `PATCH`, `PUT`, `DELETE`

Shipping options are stored in the shop database. A request is sent to the shop by proxy via Omnitron. In line with this request, the response from the shop is shown on the frontend via Omnitron.

### `GET` Shipping Options

**Path:** `api/v1/remote/1/shipping_options/`

When a GET request is thrown directly via shipping\_options/, you can get all the shipping options. If you throw a GET request such as shipping\_options/1/, you can get the shipping option with an ID value of 1. (Send a different ID value instead of 1).

### `POST` Create Shipping Option

**Path:** `api/v1/remote/1/shipping_options/`

When a post request is sent to the shipping\_options/ endpoint, like the sample data below, the creation will be completed.

```json
{
"name": "test1",          # Name
"slug": "test12",         # Slug value
"calculator": {},         # Calculator definition used to calculate
"rule": {},               # Rules defined according to the products entered by the customer
"sort_order": 12,         # priority
"description": "Test12", 
}
```

Above, there are two different values besides text and number. One is Calculator, and the other is Rule. These values are explained below.

### `PATCH` Update Shipping Option

**Path:** `api/v1/remote/1/shipping_options/{id}/`

When a patch request is sent to the shipping\_options/{id} endpoint, like the sample data below, the update will be completed. You can update the shipping option with an ID value of 1. (Send a different ID value instead of 1).

```json
{
    "calculator": {
          "name":"Free Calculator",
          "slug":"free-calculator"
          },
    "rule": {
          "name":"Any Rule",
          "slug":"any-rule"
          }
}
```

### `PUT` Update Shipping Option

**Path:** `api/v1/remote/1/shipping_options/{id}/`

When a put request is sent to the shipping\_options/{id} endpoint, like the sample data below, the update of the entire field will be completed. You can update the shipping option with an ID value of 1. (Send a different ID value instead of 1).

```json
{
    "name": "test22",
    "slug": "test22",
    "calculator": {
          "name":"Free Calculator",
          "slug":"free-calculator"
          },
    "rule": {
          "name":"Any Rule",
          "slug":"any-rule"
          },
    "sort_order": 3,
    "description": "Test14",
}
```

Above, there are two different values besides text and number. One is Calculator, and the other is Rule. These values are explained below.

### `DELETE` Shipping Option

**Path:** `api/v1/remote/1/shipping_options/{id}/`

`shipping_options/{id}/` When a delete request is sent to the shipping\_options/{id} endpoint, like the sample data below, the deletion will be completed. You can delete the shipping option with an ID value of 1. (Send a different ID value instead of 1).

## Calculator and Rule

### Calculator

It is used to calculate the price according to the total of the products added to the basket or according to different conditions.

* **FreeCalculator**: The calculator used to process the shipping fee as free of charge. Use;

```json
{
    "name":"Free Calculator",
    "slug":"free-calculator"
}
```

* **FixedPriceCalculator**: Used to process the shipping fee as a fixed price. Fixed\_price refers to the fixed shipping fee.\
  Use;

```json
{
    "fixed_price":"8.50",
    "name":"Fixed Based Calculator",
    "slug":"fixed-based-calculator"
}
```

* **AmountBasedCalculator**: Used to calculate the shipping fee according to the prices of the products in the basket. Fixed\_price refers to the fixed shipping fee. Upper\_limit refers to the upper limit of the products in the basket. Discount\_price refers to the discounted price. If upper\_limit is exceeded, discount\_price is activated.\
  Use;

```json
{
    "name":"Amount Based Calculator",
    "slug":"amount-based-calculator",
    "fixed_price":"9.90",
    "upper_limit":"150.00",
    "discount_price":"0.00"
}
```

* **WeightBasedCalculator**: Used to calculate the shipping fee according to the weight of the products in the basket. List-type weight\_ranges state lower\_limit, upper\_limit and the cargo price within these limits as the price.\
  Use;

```json
{
    "name":"Weight Based Calculator",
    "slug":"weight-based-calculator",
    "weight_ranges":[
        {
           "lower_limit":1,
           "upper_limit":5,
           "price":9.9
        },
        {
           "lower_limit":6,
           "upper_limit":10,
           "price":19.9
        },
        {
           "lower_limit":11,
           "upper_limit":15,
           "price":29.9
        }]
}
```

* **ShippingCostCalculator**: The calculator that provides cost calculation according to the shipping address. It presents the customer with the shipping cost obtained upon filtering according to the slug definition in the ShippingCost model and the address match in the ShippingCost model.\
  Use;

```json
{
    "shipping_cost_slug":"under-3000",
    "name":"Shipping Cost Calculator",
    "slug":"shipping-cost-calculator"
}
```

* **DiscountBasedCalculator**: The calculator that works according to the determined base calculator and the availability of the products in the basket. Base\_shipping contains the slug value of the base calculator. The relevant parameters are dynamically stored.\
  Use;

```json
{
    "name": "Discount Based Calculator",
    "slug": "discount-based-calculator",
    "fixed_price": "9.90",
    "upper_limit": "150.00",
    "base_shipping": "amount-based-calculator",
    "discount_price": "0.00"
}
```

* **B2CDirectCalculator**: Shipping calculator for B2C Direct. B2C Direct shipping company is inactive.\
  Use;

```json
{
    "name":"B2C Direct Calculator",
    "slug":"b2c-direct-calculator"
}
```

### Rule

The section containing the rules that the relevant shipping option should cover. Can be used in association with each other.

* **AnyRule**: Progress independent of any rule.\
  Use;

```json
{
    "name":"Any Rule",
    "slug":"any-rule"
}
```

* **WeightRule**: Establishes weight rule.\
  max\_weight covers the maximum weight. Weight\_field specifies the attribute name that defines the weight of the products in the basket. If there is none, the default is entered as 0.\
  Use;

```json
{
    "name":"Weight Rule",
    "slug":"weight-rule",
    "max_weight":1,
    "weight_field":"weight"
}
```

* **TotalVolumetricWeightRule**: Establishes total volumetric weight rule for the products in the basket. total\_max\_volumetric\_weight covers the maximum volume. volumetric\_weight\_field specifies the attribute name that defines the volume of the products in the basket. If there is none, the default is entered as 0.\
  Use;

```json
{
    "name":"Total Volumetric Rule",
    "slug":"total-volumetric-weight-rule",
    "total_max_volumetric_weight":1,
    "volumetric_weight_field":"weight"
}
```

* **HeightRule**: Establishes rule based on height.\
  max\_height covers maximum height. Height\_field specifies the attribute name that defines the height of the products in the basket. If there is none, the default is entered as 0.\
  Use;

```json
{
    "name":"Height Rule",
    "slug":"height-rule",
    "max_height":1,
    "height_field":"height"
}
```

* **CityRule**: Establishes city rule according to the entered address.\
  Use; if the Exclude field is true, it includes excluding the entered cities, if false, it only includes the entered cities. Cities is where the city IDs must go\
  Use;

```json
{
    "name":"City Rule",
    "slug":"city-rule",
    "cities":[1,2,3,4],
    "exclude":true
}
```

* **CountryRule**: Establishes country rule according to the entered address.\
  Use; if the Exclude field is true, it includes excluding the entered countries, if false, it only includes the entered countries. Countries is where the country IDs must go\
  Use;

```json
{
    "name":"Country Rule",
    "slug":"country-rule",
    "countries":[1,2,3,4],
    "exclude":true
}
```

* **TownshipRule**: Establishes township rule according to the entered address.\
  Use; if the Exclude field is true, it includes excluding the entered townships, if false, it only includes the entered townships. Townships is where the township IDs must go\
  Use;

```json
{
    "name":"Township Rule",
    "slug":"township-rule",
    "townships":[1,2,3,4],
    "exclude":true
}
```

* **DistrictRule**: Establishes district rule according to the entered address.\
  Use; if the Exclude field is true, it includes excluding the entered districts, if false, it only includes the entered districts. Districts is where the district IDs should go\
  Use;

```json
{
    "name":"District Rule",
    "slug":"district-rule",
    "districts":[1,2,3,4],
    "exclude":true
}
```

* **TimeRule**: The rule that covers the order interval determined with start\_time and end\_time.\
  Use;

```json
{
    "name":"Time Rule",
    "slug":"time-rule",
    "start_time":"15:00",
    "end_time":"18:00"
}
```

* **DayOfWeekRule**: Establishes day of week rule.\
  Use;

```json
{
    "name":"Day Of Week Rule",
    "slug":"day-of-week-rule",
    "days":["Wednesday","Thursday","Friday"]
}
```

* **BasketAmountRule**: Establishes the basket amount rule.\
  Use;

```json
{
    "name":"Basket Amount Rule",
    "slug":"basket-amount-rule",
    "max_total_amount":10
}
```

* **TotalProductAmountRule**: Establishes the total product amount rule.\
  Use;

```json
{
    "name":"Total Product Amount Rule",
    "slug":"total-product-amount-rule",
    "max_total_amount":10
}
```

* **ProductAttributeRule**: Establishes the product attribute rule.\
  Use;

```json
{
    "name":"Product Attribute Rule",
    "slug":"product-attribute-rule",
    "attribute_field":"test_attr",
    "attribute_value":"free shipping"
}
```

* **RetailStoreRule**: Establishes the retail store rule.\
  Use;

```json
{
    "name":"Retail Store Rule",
    "slug":"retail-store-rule"
}
```

* **NotRule**, **AndRule** and **OrRule**: Rule configuration is a flexible structure in which an unlimited number of nested sub-rules can be written, producing results by applying "and", "or" and "not" logic operations on custom rule sets. The "or" and "and" rules must have a "children" field, while the "not" rule must have a "child" field. Each of the custom rules has different fields.\
  Use;

```json
{
  "children": [
    {...(rule1)},
    {
      "children": [
        {
          "child": {...(rule2)},
          "name": "Not Rule",
          "slug": "not-rule"
        },
        {
          "child": {...(rule3)},
          "name": "Not Rule",
          "slug": "not-rule"
        }
      ],
      "name": "And Rule",
      "slug": "and-rule"
    }
  ],
  "name": "Or Rule",
  "slug": "or-rule"
}
```

* **RetailStoreStockRule**: Establishes the retail store stock rule.\
  Use;

```json
{
    "name":"Retail Store Stock Rule",
    "slug":"retail-store-stock-rule"
}
```

* **RegisteredUserRule**: Establishes the registered user rule.\
  Use;

```json
{
    "name":"Registered User Rule",
    "slug":"registered-user-rule"
}
```

## Shipping Company

**Path**: `api/v1/cargos/`

**Methods**: `GET`, `POST`, `PATCH`, `PUT`, `DELETE`

Shipping companies are stored on Omnitron. This is the structure that enables the integrated shipping companies to be selected by means of enums and used in relevant places.

### `GET` Shipping Company

**Path:** `api/v1/cargos/`

When a GET request is thrown directly via cargos/, you can get all the shipping companies. If you throw a GET request such as cargos/1/, you can get the shipping company with an ID value of 1. (Send a different ID value instead of 1).

### `POST` Create Shipping Company

**Path:** `api/v1/cargos/`

When a post request is sent to the cargos/ endpoint, like the sample data below, the creation will be completed.

```json
{
  "name": "test",               # Name
  "erp_code": "erp_test",       # erp code value
  "shipping_company": "ups"     # courier company enum value
}
```

**Shipping company enum values** are stated below.

### `PATCH` Update Shipping Company

**Path:** `api/v1/cargos/{id}/`

When a patch request is sent to the cargos/{id} endpoint, like the sample data below, the update will be completed. You can update the shipping company with an ID value of 1. (Send a different ID value instead of 1).

```json
{
  "shipping_company": "yurtici"
}
```

### `PUT` Update Shipping Company

**Path:** `api/v1/cargos/{id}/`

When a put request is sent to the cargos/{id} endpoint, like the sample data below, the update of the entire field will be completed. You can update the shipping company with an ID value of 1. (Send a different ID value instead of 1).

```json
{
  "name": "test 001",             # name
  "erp_code": "erp_test_001",     # erp code value
  "shipping_company": "mng"       # courier company enum value
}
```

**Shipping company enum values** are stated below.

### `DELETE` Shipping Company

**Path:** `api/v1/cargos/{id}/`

When a delete request is sent to the cargos/{id} endpoint, like the sample data below, the deletion will be completed. You can delete the shipping company with an ID value of 1. (Send a different ID value instead of 1).

Example path, `cargos/2/`

### `GET` Shipping Company Enum Values

**Path:** `api/v1/cargos/shipping_companies/`

You can get the defined shipping company enum values.

**Response**

```json
{
    "shipping_companies": {
        "hoopkapida": "Hoopkapida Kargo",
        "k_sende": "Kargom Sende",
        "novaposhta": "Nova Poshta",
        "scotty": "Scotty Cargo",
        "arvato": "Arvato",
        "tmmexpress": "TMM Express",
        "fast_cargo": "Fast Cargo",
        "ptt": "Ptt",
        "murat_lgc": "Murat Lojistik",
        "mng": "MNG Kargo",
        "loomis": "Loomis",
        "jetizz": "Jetizz",
        "asil": "Asil Kargo",
        "ups_intl": "UPS International",
        "r2s": "R2S Cargo",
        "giz": "Giz",
        "tyexpress": "Tyexpress",
        "other": "Other",
        "fancourier": "Fan Courier",
        "mylerzsdd": "Mylerz Same Day Delivery",
        "k_gelsin": "Kolay Gelsin",
        "ismail": "Is-Mail Kargo",
        "aras": "Aras Kargo",
        "packupp": "Packupp",
        "ay_cargo": "Ay Kargo",
        "yurtici": "Yurtiçi Kargo",
        "bringo": "Bringo",
        "cainiao": "Cainiao",
        "netkargo": "NetKargo",
        "boomex": "Boomex",
        "carrtell": "Cartell",
        "b2c_direct": "B2C Direct",
        "horoz": "Horoz",
        "aramex": "Aramex",
        "birgunde": "Bir Günde Kargo",
        "dhlexpress": "DHL Express",
        "chrono": "Chrono Diali Courier",
        "mylerz": "Mylerz Cargo",
        "bovo": "Bovo",
        "acs": "ACS Kargo",
        "speeta": "Speeta",
        "dpd": "DPD Cargo",
        "droplight": "DropLight",
        "gelal": "Gelal",
        "surat": "Sürat Kargo",
        "in_post": "In Post",
        "gls": "GLS Logistic",
        "kargo_ist": "Kargo İstanbul",
        "ups": "UPS",
        "hbexpress": "Hepsi Express"
    }
}
```

## Tracking Number

After the successful payment of the products in the customer basket, the numbers of the orders and tracking numbers are collected specifically (cancellation\_waiting, confirmation\_waiting, approved, preparing, shipped, shipped\_and\_informed, ready\_for\_pickup, attempted\_delivery and delivered), and sent to the integrated and adjusted companies in the enums above. After this shipment, the cargo tracking numbers are added by updating the tracking\_number fields of the orders. Customers using the online store are directed to the cargo tracking site of the companies listed in the above enums with the relevant cargo tracking number. With tasks running periodically in the background, this process is automated from end to end.

## Invoice Number

Thanks to our layer inter-integrated to the ERP systems used for issuing invoices, the numbers of the invoice issued upon order are sent to the Omnitron API with an update request. This allows for the invoice number to be processed on the order.
