Removing old 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 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.

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. 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).

    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 cartcategory 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 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).

    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.