Please use extreme caution when using this modification. It is unforgiving. Make a mistake and you're restoring your database. There is no "Undo". Seriously. There is also no "Are you sure?" when using this modification. Real site admins don't need it (plus I don't know how to add one)
There are many times where I have found the need to delete an order. It usually involves my own testing or an unusual payment processing failure.
When an order gets messed up, the customer usually places another order, if they even know there was a problem. Usually this results in 3-4 bad orders on the Admin side. there's no way to delete them, so you're forced to sort "around" them as you work to process your business. It also forces the customer to live with a really confusing order history.
This modification allows the Admin to delete a single or group of orders right from Admin screen using the "Update Selected Orders" feature.
How it works
This modification uses the same concept already built into the Update Selected Orders dropdown. Just click the checkboxes for the orders to delete, select the "Delete" dropdown option and click Go.
First make a backup copy of your ~/Admin/Orders/default.aspx and default.aspx.cs files. These are the files we will be changing in this modification.
Edit ~/Admin/orders/Default.aspx file and look for the start of the dropdown list control – here is some of this code:
| <asp:DropDownList ID="BatchAction" runat="server">
<asp:ListItem Text="Process Payment" Value="PAY"></asp:ListItem>
<asp:ListItem Text="Mark Shipped" Value="SHIP"></asp:ListItem>
<asp:ListItem Text="Mark Shipped with Options" Value="SHIPOPT"></asp:ListItem>
<asp:ListItem Text="Cancel" Value="CANCEL"></asp:ListItem>
Directly below the first "————" ListItem entry you see, add this code:
| <asp:ListItem Text="* DELETE *" Value="DELETE"></asp:ListItem>
Now edit the ~/Admin/Orders/Default.aspx.cs file. Find the code located in the BatchButton_Click function that looks like this:
| case "SHIPOPT":
Response.Redirect("Batch/Ship.aspx?orders=" + GetOrderList(orderIds));
We need to Insert another CASE section of code like this directly below the "break;" line. So add the following code as described:
| case "DELETE":
int DelCount = 0;
foreach (int orderId in orderIds)
Order order = OrderDataSource.Load(orderId);
if (order != null)
messages.Add("Order #" + order.OrderId + " deleted.");
messages.Add(DelCount + " orders deleted.");
It's critical you test this in your development environment first. There is no "Undo" feature – once an order is deleted, it's gone. Note how you can delete one order at a time, or delete multiple orders in a single command. Test both scenarios and confirm the properly selected orders were removed and no others.
Deleting an order cascades through the other files automatically. Payment records, notes and history, shipments etc will also be automatically deleted. There should be no trace of the order left when the command is finished.
Order management is a key point in the business process where mistakes can be made. Clearing out unwanted orders helps the admin keep a clean running store with less potential for errors. It also gives the customer a good looking order history to review their purchases.