Deleting expired shopping carts from the database

When customers add products to their shopping carts and then leave the site 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 the number of days after which the system considers shopping carts as old.
  2. Set a regularly launched task that removes the shopping carts from the database.

Setting the number of days after which shopping carts are considered expired

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. If you run multiple sites on your instance and want all sites to 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).

    If you are not sure what to choose, see Choosing site or global e-commerce configuration. If you are not sure about specifics of configuring in these applications, see Configuring e-commerce settings for a specific site or globally.

  2. In the Shopping cart category of the Store configuration -> General tab, configure the Clear content of old shopping cart after (days) setting:

    • 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, for example 30.
  3. Click Save.

The system updates the settings. Any scheduled tasks working with this setting operate 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).
    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 according to your needs.

  6. Click Save.

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

See the task on the sampleDancing Goatsite as an example.