Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Most customers use quartz or some of other type of service to periodically delete old carts after a certain number of days.
OrderSearchParameters parameters = new OrderSearchParameters(); parameters.SqlMetaWhereClause = String.Format("META.Modified < '{0}''", DateTime.Now.AddDays(-60).ToUniversalTime().ToString("s")); OrderSearchOptions options = new OrderSearchOptions(); int records = 0; Cart[] expiredCarts = OrderContext.FindCarts(parameters, options, out records);
Marks solution is not complete and has a typo (double single quotes - thank you episerver support for this one), and the example will not work for R2 SP2. And this thread is still number 1 on google when you search for this topic.
Here is the correct solution:
var parameters = new OrderSearchParameters { SqlMetaWhereClause = String.Format("META.Modified < '{0}'", DateTime.Now.Subtract(_ageToDelete).ToUniversalTime().ToString("s")) }; var searchOptions = new OrderSearchOptions {RecordsToRetrieve = _collectionSize, CacheResults = false}; searchOptions.Classes.Add("ShoppingCart"); int records; var cartToCleanUp = _orderContext.FindCarts(parameters, searchOptions, out records);
How can we clear baskets that have been expired, and didnot turned into purchase orders.