Try our conversational search powered by Generative AI!

How can we clear baskets that have been expired

Vote:
 

How can we clear baskets that have been expired, and didnot turned into purchase orders.

#59346
Jun 01, 2012 16:45
Vote:
 

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

    

#59380
Edited, Jun 04, 2012 20:16
Vote:
 

Many Thanks Mark!

#59699
Jun 22, 2012 12:16
Vote:
 

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 = _collectionSizeCacheResults = false};
searchOptions.Classes.Add("ShoppingCart");
 
int records;
var cartToCleanUp = _orderContext.FindCarts(parameterssearchOptionsout records);

 

#84969
Apr 10, 2014 12:14
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.