Developer forum

Forum » Development » Automatic clean up orders

Automatic clean up orders


Reply
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

Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
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
 
Reply
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

 

You must be logged in to post in the forum