# Widgets

Widgets are dynamic UI components based on schemas, encompassing elements like sliders and banners that are deployable within the storefront. These elements can also store information regarding product collections and can be used for displaying products on the storefront. Widgets are formally defined within Omnitron and can be retrieved by querying them using their unique widget slug identifier.

### Model

#### Widget

| field                         | type          | description                                     |
| ----------------------------- | ------------- | ----------------------------------------------- |
| name                          | CharField     | The name of the widget.                         |
| slug                          | SlugField     | A unique slug for identifying the widget.       |
| template                      | SlugField     | The template used for rendering the widget.     |
| widget\_type                  | WidgetType    | The widget type that holds the widget's schema. |
| created\_date                 | DateTimeField | The date when the widget was created.           |
| modified\_date                | DateTimeField | The date when the widget was last modified.     |
| attributes                    | JSONField     | Attributes of the widget.                       |
| attributes\_kwargs            | JSONField     | Information about the widget's attributes.      |
| content\_type                 | ContentType   | The content type of the widget.                 |
| localized\_attributes         | JSONField     | Localized attributes specific to the widget.    |
| localized\_attributes\_kwargs | JSONField     | Information about localized attributes.         |

#### ProductCollectionWidget

| field                         | type                 | description                                              |
| ----------------------------- | -------------------- | -------------------------------------------------------- |
| name                          | CharField            | The name of the widget.                                  |
| slug                          | SlugField            | A unique slug for identifying the widget.                |
| template                      | SlugField            | The template used for rendering the widget.              |
| product\_collection           | ProductCollection    | The product collection linked to the widget.             |
| product\_limit                | PositiveIntegerField | The maximum number of products to display in the widget. |
| widget\_type                  | WidgetType           | The widget type that holds the widget's schema.          |
| created\_date                 | DateTimeField        | The date when the widget was created.                    |
| modified\_date                | DateTimeField        | The date when the widget was last modified.              |
| attributes                    | JSONField            | Attributes of the widget.                                |
| attributes\_kwargs            | JSONField            | Information about the widget's attributes.               |
| content\_type                 | ContentType          | The content type of the widget.                          |
| localized\_attributes         | JSONField            | Localized attributes specific to the widget.             |
| localized\_attributes\_kwargs | JSONField            | Information about localized attributes.                  |

### Endpoints

#### `GET` Retrieve a Widget Info

This method is used to get widget information that have been defined in Omnitron.

**Path:** `https://{commerce_url}/widgets/<widget-slug>/`

**Example Response**

Here's an example response of a product collection widget:

```json
{
  "name": "Campaign",
  "slug": "x-campaign",
  "attributes": {
    "abc": "xyz"
  },
  "template": "widgets/campaign.html",
  "products": [
    {
      "pk": 10,
      "sku": "12612662136",
      ...
    },
    {
      "pk": 11,
      "sku": "12612662137",
      ...
    },
    ....
  ]
}
```

Here's an example response of a simple widget:

```json
{
  "attributes": {
    "sliders": [
      {
        "value": {
          "name": "Kampanya",
          "slug": "kampanya"
        },
        "kwargs": null
      },
      {
        "value": {
          "name": "\u0130ndirim",
          "slug": "indirim"
        },
        "kwargs": null
      }
    ],
    "slider_items": [
      {
        "value": {
          "url": "#",
          "slider_slug": "kampanya",
          "alt": "resim",
          "image": "assets/img/slider.jpg",
          "title": "baslik"
        },
        "kwargs": null
      },
      {
        "value": {
          "url": "#",
          "slider_slug": "indirim",
          "alt": "resim",
          "image": "assets/img/slider2.jpg",
          "title": "baslik"
        },
        "kwargs": null
      },
      {
        "value": {
          "url": "#",
          "slider_slug": "kampanya",
          "alt": "resim",
          "image": "assets/img/slider2.jpg",
          "title": "baslik"
        },
        "kwargs": null
      },
      {
        "value": {
          "url": "#",
          "slider_slug": "indirim",
          "alt": "resim",
          "image": "assets/img/slider.jpg",
          "title": "baslik"
        },
        "kwargs": null
      }
    ]
  },
  "name": "Slider",
  "template": "index/slider.html",
  "slug": "slider"
}
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.akinon.com/commerce/widgets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
