Delete Old Orders
Permanently remove orders older than the configured retention period
Overview
This task permanently deletes orders that are older than a specified threshold. It is designed for data retention compliance and database maintenance, removing both the search index entries and the underlying storage records for orders beyond their retention period.
Identifier
| Property | Value |
|---|---|
| Implementation Type | DeleteOldOrdersScheduledTask |
| Group | Orders |
| Type | Delta |
When to Use
Enable this task when you need:
- Compliance with data retention policies (GDPR, etc.)
- Database size management for long-running installations
- Removal of historical orders beyond legal retention requirements
- Storage cost optimization
Configuration Properties
| Property | Type | Required | Description |
|---|---|---|---|
DeleteOrdersThreshold | int | Yes | Number of years after which orders are deleted. Must be 2 or higher. Configured in Order Settings, not task properties. |
Behavior
What It Does
- Reads the deletion threshold from Order Settings (in years)
- Validates that the threshold is at least 2 years (safety check)
- Calculates the cutoff date based on current date minus threshold years
- Queries for all orders created before the cutoff date
- Processes orders in batches for efficiency
- Deletes orders from both the search index and permanent storage
- Reports the total number of orders deleted
Safety Measures
- Minimum threshold of 2 years prevents accidental deletion of recent orders
- Orders with a creation date of minimum value (system default) are excluded
- Task fails if threshold is not configured or is below 2 years
Prerequisites
DeleteOrdersThresholdmust be configured in Order Settings- Threshold value must be 2 or greater
Side Effects
- Permanent deletion of order data from all storage locations
- Frees up storage space in both search index and database
- Associated order history and event logs may be affected
- This operation cannot be undone
Example Configuration
First, ensure the Order Settings include the threshold:
Then configure the scheduled task:
Recommended Schedule
Run weekly during off-peak hours (0 3 * * 0 - Sundays at 3 AM) to minimize impact on system performance. This is a heavy operation that should not run during business hours.
Related Tasks
- Cancel Expired Orders - Cancel orders before deletion
- Cancel Expired Click and Collect - Handle pickup order expirations
