Hi
In our applications with webshops we would like to clean op old carts that did not became an order.
Is there an automatic function to call to clean up the orders / orderlines?
Gr
Martijn
Developer forum
E-mail notifications
Automatic clean up orders
Posted on 15/12/2010 10:30:14
Replies
Jeppe Eriksson Agger
Posted on 15/12/2010 15:32:55
Hi Martijn
There's no way to do this automatically.
A way to do it is to get a collection of orders from the database, find the ones you want to delete and then deleting them--the properties IsCart and Complete will be useful for this. This will be enough in your case because deleting an order will also delete all orderlines on that order.
Eg.:
public void DeleteOrphanedOrders()
{
OrderCollection orders = new OrderCollection();
orders.Load("SELECT * FROM EcomOrders"); // You might want to limit this query to more
// or less only contain the ones you want :-)
foreach (var order in orders)
{
if (order.IsCart && !order.Complete)
order.Delete(); // Deleting an order also deletes the associated orderlines
}
}
I haven't tested this code, but it should work, or at least give you an idea as to what to do :-)
- Jeppe
There's no way to do this automatically.
A way to do it is to get a collection of orders from the database, find the ones you want to delete and then deleting them--the properties IsCart and Complete will be useful for this. This will be enough in your case because deleting an order will also delete all orderlines on that order.
Eg.:
public void DeleteOrphanedOrders()
{
OrderCollection orders = new OrderCollection();
orders.Load("SELECT * FROM EcomOrders"); // You might want to limit this query to more
// or less only contain the ones you want :-)
foreach (var order in orders)
{
if (order.IsCart && !order.Complete)
order.Delete(); // Deleting an order also deletes the associated orderlines
}
}
I haven't tested this code, but it should work, or at least give you an idea as to what to do :-)
- Jeppe
Posted on 15/12/2010 16:24:50
Hi Jeppe
Thanx for your quick reply.
I will make my own function, based on the code you provided.
With a scedulded task I will run the function occasionally
Gr.
Martijn
Thanx for your quick reply.
I will make my own function, based on the code you provided.
With a scedulded task I will run the function occasionally
Gr.
Martijn
You must be logged in to post in the forum