# Adding discount codes

Before discount codes can be used in the frontend, they must be set-up in the backend. This can be done by reaching out to a KASKO certified backend developer.

## Enabling coupon codes in the frontend

After the discount codes have been enabled for the product, discount codes can be implemented in the frontend. This can be done by following these steps:

Set field definition for `coupon_code`:

```json
{
  "discount": [
    {
      "name": "coupon_code",
      "validation": "string"
    }
  ]
}
```

Add the coupon code component to the flow:

```json
{
  "type": "form-coupon-code",
  "config": {
    "content_key": {
      "input_label": "form.coupon_code.label",
      "input_placeholder": "form.coupon_code.placeholder",
      "button": "form.coupon_code.button"
    }
  }
}
```

Alternatively, this snippet can be used for greater flexibility:

```json
{
  "type": "grid",
  "config": {
    "grid": [
      {
        "class": "col-xs-8",
        "components": [
          {
            "type": "form-input",
            "config": {
              "show_label": true,
              "field_name": "coupon_code"
            }
          }
        ]
      },
      {
        "class": "col-xs-4",
        "components": [
          {
            "type": "form-input-button",
            "config": {
              "type": "button",
              "field_name": "coupon_submit",
              "field_value": true,
              "content_key": "form.coupon_code.button"
            }
          }
        ]
      }
    ]
  }
}
```


---

# 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://docs.kasko.io/kasko-frontend-documentation/guides/discount-codes.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.
