---
title: Adding coupon code fields to MVC checkout processes
related:
  - https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-order-discounts.md
  - https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-buy-x-get-y-discounts.md
  - https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-free-shipping-offers.md
  - https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-discount-coupons/working-with-product-coupons.md
  - https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts.md
  - https://docs.kentico.com/k10/e-commerce-features/customizing-and-developing-your-store/discount-related-customizing.md
  - https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc.md
  - https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

The Kentico E-commerce Solution provides coupon codes for several types of [discounts](https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts.md):

- [Order discounts](https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-order-discounts.md)
- [Buy X Get Y discounts](https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-buy-x-get-y-discounts.md)
- [Free shipping offers](https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-free-shipping-offers.md)
- [Product coupons](https://docs.kentico.com/k10/e-commerce-features/managing-your-store/discounts/working-with-discount-coupons/working-with-product-coupons.md)

[Customers](https://docs.kentico.com/k10/e-commerce-features/managing-your-store/customers.md) that obtained a coupon code are eligible to some discount (based on configuration of the discount).

When building a [checkout process on an MVC site](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/checkout-process-in-mvc.md), you may want to place a coupon code text box for customers. They can type their coupon code into a specified text box and apply the coupon. The system then validates whether the coupon code provides a discount. In a Kentico MVC project, the [Kentico.Ecommerceintegration package](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md) holds the coupon code information.

To place the coupon code field on your MVC site:

1. Open your MVC project in Visual Studio.
2. Add a method for setting and validation of coupon codes to your controller using the **SetCouponCode** method.

   1. Add a method that sets and validates the coupon code:

      ```csharp

              /// <summary>
              /// Applies the specified coupon code to the specified shopping cart.
              /// </summary>
              /// <param name="cart">Shopping cart to which the coupon code is applied.</param>
              /// <param name="couponCode">Coupon code to be applied.</param>
              [HttpPost]
              private bool ApplyCouponCode(ShoppingCart cart, string couponCode)
              {
                  // Assigns the coupon code to the shopping cart
                  cart.CouponCode = couponCode;
                  cart.Save();

                  // Returns whether the code is valid (i.e. whether the coupon code applies any discount or is empty)
                  return cart.HasUsableCoupon;
              }


      ```
   2. Call the method from the POST action of [displaying the shopping cart](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/checkout-process-in-mvc/using-a-shopping-cart-on-mvc-sites.md).
3. In the shopping cart's view, create a form with a coupon code text box and an apply button.

   ```csharp

   @* Coupon code text box and apply button *@
   @using (Html.BeginForm("ShoppingCart", "Checkout", FormMethod.Post))
   {
       <input type="text" name="CouponCode" value="@Model.CouponCode" />
       <input type="submit" name="ApplyCouponCode" value="Apply" />
   }


   ```

   > **Tip:** Add a button for continuing with the next [checkout process](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/checkout-process-in-mvc.md) step to the form. This ensures that the customer does not need to click the apply button to use the coupon.

The system now accepts coupon codes typed during the checkout process and customers can get their discounts.
