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:
- Set the number of days after which the system considers shopping carts as old.
- 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.
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.
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.
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
Open the Scheduled tasks application.
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).
Click New task.
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)
Enter the other properties according to your needs.
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.