# Retail Stores

Embodies the actual retail locations where the product is sold.

Users can add/delete/update stores in Omnitron with `GET`, `POST`, `PATCH`, `PUT` and `DELETE` requests via `api/v1/retail_stores/` endpoint.

## `GET` Retail Stores

Path: `api/v1/retail_stores/`

Path: `api/v1/retail_stores/&lt;pk>/`

When a `GET` request is made directly from retail\_stores/, users can get all stores. If a user sends a `GET` request like `retail_stores/1/` they will get the store with ID value 1 (instead of 1 send the id you need). Associated data has only an ID value.

```json
{
   "count": 5,
   "next": null,
   "previous": null,
   "results": [
       {
           "pk": 1,
           "name": "Shop 1",
           "township": 1,
           "district": 5,
...
```

Path: `api/v1/retail_stores/detailed/`

Path: `api/v1/retail_stores/<pk>/detailed/`

Sending a request to the detailed/ endpoint will result in a list of properties of the related data.

```json
{
   "count": 5,
   "next": null,
   "previous": null,
   "results": [
       {
           "pk": 1,
           "name": "Shop 1",
           "township": {
               "pk": 1,
               "is_active": true,
               "name": "Test Township 1",
               "city": {
                   "pk": 1,
...
```

## `POST` Create a Retail Store

Parameters for creating a retail store are displayed in the table below.

| **Parameter**       | **Data Type** | **In** | **Required** | **Description**                                                                              |
| ------------------- | ------------- | ------ | ------------ | -------------------------------------------------------------------------------------------- |
| authorization       | string        | header | YES          | [The API key of the customer’s account](https://apidocs.akinon.com/omnitron/getting-started) |
| name                | string        | body   | YES          | Name of the store                                                                            |
| address             | string        | body   | YES          | Address details                                                                              |
| township            | ID            | body   | YES          | Township ID value                                                                            |
| phone\_number       | string        | body   | YES          | Phone number                                                                                 |
| channels            | ID List       | body   | YES          | Sales channel ID values                                                                      |
| store\_type         | ID or null    | body   | YES          | Store type ID value                                                                          |
| fax\_phone\_number  | string        | body   | YES          | Fax phone number                                                                             |
| click\_and\_collect | Boolean       | body   | YES          | Permission for getting products from Store                                                   |
| store\_hours        | List          | body   | YES          | Work hours                                                                                   |
| is\_active          | Boolean       | body   | YES          | Activity status                                                                              |
| district            | ID            | body   |              | District ID value                                                                            |
| latitude            | number        | body   |              | Latitude                                                                                     |
| longitude           | number        | body   |              | Longitude                                                                                    |
| kapida\_enabled     | boolean       | body   |              | A field specific to a project                                                                |
| fast\_delivery      | boolean       | body   |              | Status of fast delivery                                                                      |
| erp\_code           | string        | body   |              | Store erp code                                                                               |

When a post request is made to the retail\_stores/ endpoint, such as the example data below, the creation process takes place.

Path: `api/v1/retail_stores/`

**Request**

```json
{

"name":"test-u-1",
"address":"test address text",
"township":1,
"phone_number":"02129998877",
"channels":[1],
"is_active":true,
"store_type": null,
"fax_phone_number": "02129998877",
"click_and_collect": false,
"store_hours": [
["09:00:00","19:00:00"],
["09:00:00","19:00:00"],
["09:00:00","19:00:00"],
["09:00:00","19:00:00"],
["09:00:00","19:00:00"],
["09:00:00","19:00:00"],
["09:00:00","19:00:00"]
]
}
```

**Response**

```json
{
   "pk": 11,
   "name": "test-u-1",
   "township": 1,
   "district": null,
   "address": "test address text",
   "phone_number": "02129998877",
   "fax_phone_number": "02129998877",
   "image": null,
   "store_hours": [
       [
           "09:00:00",
           "19:00:00"
       ],
       [
           "09:00:00",
           "19:00:00"
       ],
       [
           "09:00:00",
           "19:00:00"
       ],
       [
           "09:00:00",
           "19:00:00"
       ],
       [
           "09:00:00",
           "19:00:00"
       ],
       [
           "09:00:00",
           "19:00:00"
       ],
       [
           "09:00:00",
           "19:00:00"
       ]
   ],
   "latitude": null,
   "longitude": null,
   "is_active": true,
   "click_and_collect": false,
   "store_type": null,
   "kapida_enabled": false,
   "fast_delivery": false,
   "config": {},
   "group": null,
   "sort_order": null,
   "channels": [
       1
   ],
   "erp_code": null,
   "modified_date": "2022-12-23T09:33:42.986845Z",
   "created_date": "2022-12-23T09:33:42.986832Z"
}

```

Access the data below for the District, Township, Channels and Store Type that you will need in order to use the above request.

District: Get it by sending a GET request to the `api/v1/districts/` endpoint.

Township: Get it by sending a GET request to the `api/v1/townships/` endpoint.

Channels: Get it by sending a GET request to the `api/v1/channels/` endpoint.

Store Type: : Get it by sending a GET request to the `api/v1/retailstore_type/` endpoint.

## `PATCH` Modify an Existing Retail Store

When a patch request, such as the sample data below, is sent to the retail\_stores/ID/ endpoint, the update process will be completed. Update the store whose ID value is 1 (replace 1 with the ID value you need).

Path: `api/v1/retail_stores/{pk}/`

```json
{
  "name": "New Test Retail Store",                          # Retail Store Name
  "township": 453,                                          # Township ID Value
  "address": "Test district Test street, Test building",    # Address Detail
  "phone_number": "02129998811",                            # Phone Number
  "district": 32445,                                        # District ID Value
}

```

Access the data below for the District, Township, Channels and Store Type that you will need to use the above request.

District: Get it by sending a GET request to the `api/v1/districts/` endpoint.

Township: Get it by sending a GET request to the `api/v1/townships/` endpoint.

Channels: Get it by sending a GET request to the `api/v1/channels/` endpoint.

Store Type: Get it by sending a GET request to the `api/v1/retailstore_type/` endpoint

## `PUT` Modify an existing Retail Store

When a `PUT` request is sent like the example data below to the retail\_stores/ID/ endpoint, the entire field will be updated. Update the store whose ID value is 1 (replace 1 with the ID value you need).

Path: `api/v1/retail_stores/{pk}/`

```json
{
  "name": "Test Retail Store",                   # Retail Store Name
  "township": 454,                               # Township ID Value
  "address": "Test district test street",        # Address Detail
  "phone_number": "02129998877",                 # Phone Number
  "fax_phone_number": null,                      # Fax Phone Number
  "is_active": true,                             # Status of Activity
  "click_and_collect": false,                    # Permission for getting products from Store
  "store_type": null,                            # Store Type ID Value
  "erp_code": "test_retail_store",               # ERP Code Value
  "district": 35485,                             # District ID Value
  "channels": [1],                               # Sale Channels ID Values
  "store_hours": [                               # Work Hours
    ["09:00", "18:00"],
    ["09:00", "18:00"],
    ["09:00", "18:00"],
    ["09:00", "18:00"],
    ["09:00", "18:00"],
    ["09:00", "12:00"],
    ["10:00", "12:00"]
  ]
}

```

Access the data below for the District, Township, Channels and Store Type that you will need to use the above request.

District: Get it by sending a GET request to the `api/v1/districts/` endpoint.

Township: Get it by sending a GET request to the `api/v1/townships/` endpoint.

Channels: Get it by sending a GET request to the `api/v1/channels/` endpoint.

Store Type: Get it by sending a GET request to the `api/v1/retailstore_type/` endpoint.

## `DELETE` Retail Store

When a delete request is sent like the example data below to the retail\_stores/ID/ endpoint the deletion will be completed. Delete the store with ID value of 1 (substitute with ID value you need). This will update the is\_active value to False, but won’t delete the relevant model.

Path: `api/v1/retail_stores/{pk}/`

## Special Endpoints

***

**add\_districts**

Provide a new neighborhood definition to the config value of the store by sending a POST request to the `/api/v1/retail_stores/{retail_stores_id}/add_districts/` endpoint.

### `POST` Add Districts to a Retail Store

Path: `/api/v1/retail_stores/{retail_stores_id}/add_districts/`

```json
{
  "districts": [35482, 35411, 35213], # defining multiple district values
}

```

***

**remove\_districts**

Send a `POST` request to `/api/v1/retail_stores/{retail_stores_id}/remove_districts/endpoint` so that a new neighborhood is deleted in the config value of the store.

### `POST` Remove Districts in a Retail Store

Path: `/api/v1/retail_stores/{retail_stores_id}/remove_districts/`

```json
{
  "districts": [35482, 35411], # removing multiple district values
}
```
