---
title: Removing old shopping carts from the database
related:
  - https://docs.kentico.com/k11/configuring-kentico/scheduling-tasks.md
  - https://docs.kentico.com/k11/configuring-kentico/scheduling-tasks/reference-scheduled-task-properties.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).

When [customers](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/customers.md) add [products](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/products.md) to their shopping carts and then leave the [site](https://docs.kentico.com/k11/configuring-kentico/managing-sites.md) without finishing their purchases, the shopping cart is saved in the database along with the products in the cart. This can cause bloating of your database and in the end, it can slow down the whole website.

To prevent bloating of the database:

1. [Set up after how many days shopping carts are considered as old.](#setting-up-after-how-many-days-shopping-carts-are-considered-as-old)
2. [Set a regularly launched task that removes the shopping carts from the database.](#configuring-a-scheduled-task-that-deletes-old-shopping-carts)

## Setting up after how many days shopping carts are considered as old

As with most of the e-commerce settings, you can set the time after the shopping carts are considered as old for [the current site or globally for all your sites running on the Kentico instance](https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/choosing-site-or-global-e-commerce-configuration.md). If you run more sites on your instance and all sites should use the same number of days, use global settings; otherwise, we recommend that you choose site settings.

1. Open the **Store configuration** application (if you want to specify the setting for the current site) or the **Multistore configuration** application (if you want to specify the setting globally).

   > **Tip:** If you are not sure what to choose, see [Choosing site or global e-commerce configuration](https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/choosing-site-or-global-e-commerce-configuration.md). If you are not sure about specifics of configuring in these applications, see [Configuring e-commerce settings for a specific site or globally](https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/choosing-site-or-global-e-commerce-configuration/configuring-e-commerce-settings-for-a-specific-site-or-globally.md).
2. In the **Shopping cart**category of the **Store configuration -> General** tab, enter the following properties to the **Clear content of old shopping cart after (days)** field:

   - Clear the _Inherit from global settings_ option (only if you work in the **Store configuration** application).
   - Type the desired number of days after which shopping carts should be considered as old and should be deleted to the text box, for example _30_.
3. Click **Save**.

The system updates the settings and [scheduled tasks](https://docs.kentico.com/k11/configuring-kentico/scheduling-tasks.md) working with this setting (not any yet) operates with the specified number of days.

## Configuring a scheduled task that deletes old shopping carts

1. Open the **Scheduled tasks** application.
2. In the **Site** selector, select the desired site (if you want to create the scheduled task for a specific site) or leave the _(global)_ option (if you want to create the scheduled task [globally](https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/choosing-site-or-global-e-commerce-configuration.md)).

   ![Switching to a specific site](https://docs.kentico.com/docsassets/k11/removing-old-shopping-carts-from-the-database/switching_to_site.png "Switching to a specific site")
3. Click **New task**.
4. Enter the following properties:

   - **Task display name**: Clear content of old shopping carts
   - **Task provider**:
     - _Assembly name_: CMS.Ecommerce
     - _Class_: CMS.Ecommerce.ShoppingCartCleaner
   - **Task enabled**: Yes (selected)
5. Enter the [other properties](https://docs.kentico.com/k11/configuring-kentico/scheduling-tasks/reference-scheduled-task-properties.md) according to your needs.
6. Click **Save**.

The system now clears the database from the shopping carts of the unfinished purchases.

> **Tip:** See the task on [the sampleDancing Goatsite](https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/installing-the-e-commerce-sample-sites.md) as an example.
