https://world.episerver.com/documentation/developer-guides/commerce/orders/Searching-for-orders/
You can set it to shopping carts and build ypur own query. Note that you should check how the resulting query ends up so it's as performant as you want it to be.
If you are using the (old) concrete cart, then as Joel said you can use the order search API to find the carts.
int startRowIndex = 0; OrderSearchParameters parameters = new OrderSearchParameters { SqlMetaWhereClause = $"Meta.Modified > GETDATE() - 7", }; OrderSearchOptions options = new OrderSearchOptions {Namespace = "Mediachase.Commerce.Orders"}; options.Classes.Add(OrderContext.ShoppingCartClassType); options.RecordsToRetrieve = 50; int totalRecords; do { options.StartingRecord = startRowIndex; Cart[] carts = OrderContext.Current.FindCarts(parameters, options, out totalRecords); if (carts != null) { foreach (Cart cart in carts) { //Do stuffs } totalRecords = carts.Count(); } } while (totalRecords > 0);
If you are using serializable cart then things are a bit more complicated as you would have to use an internal class for that
var cartFilter = new CartFilter() { ModifiedFrom = DateTime.UtcNow.AddDays(-7), StartingRecord = 0, RecordsToRetrieve = 100 }; do { var carts= _serializableCartDB.Service.FindCarts(cartFilter)); foreach (var cart in carts) { } totalRecords = carts.Count(); } while (totalRecords > 0);
@joel:
Do you know how such a query would look (retrieving all carts not older than 7 days)?
OrderSearchOptions searchOptions = new OrderSearchOptions();
searchOptions.CacheResults = false;
searchOptions.StartingRecord = 0;
searchOptions.RecordsToRetrieve = 10000;
searchOptions.Namespace = "Mediachase.Commerce.Orders";
OrderSearchParameters parameters = new OrderSearchParameters();
searchOptions.Classes.Add("ShoppingCart");
parameters.SqlMetaWhereClause = "";
parameters.SqlWhereClause = "";
Cart[] cartCollection = OrderContext.Current.FindCarts(parameters, searchOptions);
Thanks!
I would like to get all saved shopping carts from 7 days back (for all customers)? Is there some way to do this with the API?
I am using Commerce 11.