How to Delete Baskets
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
You can delete baskets in the following ways:
Create an array that contains the OrderGroupId attribute of each Basket instance that you want to delete. Then pass the array to the DeleteBaskets method of the BasketManager object.
Create a SearchClause object to represent the conditions that a basket must match in order to be deleted. Then pass the SearchClause object to the DeleteBaskets method on the BasketManager object.
This topic explains how to delete baskets by specifying conditions that the baskets must match.
To delete baskets
Create an OrderManagementContext object.
For more information about creating an OrderManagementContext object, see How to Create an OrderManagementContext Object.
Get the BasketManager object from the OrderManagementContext object.
Create a SearchClause object that will match all of the baskets that you want to delete.
For more information about creating a SearchClause object, see How to Create a Search Clause.
Call the DeleteBaskets method of the BasketManager object and pass the SearchClause object as a parameter.
Example
The following code example deletes baskets that were created on or before January 1, 2006.
using System;
using System.Data;
using System.Globalization;
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Orders;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
// Create the OrderManagementContext object. This
// example accesses the Orders System in local mode by
// creating an OrderSiteAgent object. You could also
// access the Orders System in agent mode by creating
// an OrderServiceAgent object.
// In the following, replace "StarterSite" with the
// name of your site.
OrderSiteAgent ordersAgent = new OrderSiteAgent("StarterSite");
OrderManagementContext context = OrderManagementContext.Create(ordersAgent);
BasketManager manager = context.BasketManager;
// Create a search clause.
DataSet searchableProperties = manager.GetSearchableProperties(CultureInfo.CurrentUICulture.ToString());
SearchClauseFactory searchClauseFactory = manager.GetSearchClauseFactory(searchableProperties, "Basket");
SearchClause clause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.OnOrBefore, "Created", new DateTime(2006, 1, 1));
// Delete baskets that match the conditions.
int recordsDeleted;
manager.DeleteBaskets(clause, out recordsDeleted);
Console.WriteLine("Deleted " + recordsDeleted.ToString() + " records.");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.Message);
if (ex.InnerException != null)
{
Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
}
Console.ReadLine();
}
}
}
}
Your database must contain baskets that were created on or before January 1, 2006 for this example to delete any records.
Compiling the Code
To run this code example, create a console application and add references to the following assemblies:
Microsoft.CommerceServer.CrossTierTypes.dll
Microsoft.CommerceServer.Orders.CrossTierTypes.dll
Microsoft.CommerceServer.Orders.DataManagement.dll