How to add a Delete function to the Orders admin screen

This forum is where we'll mirror posts that are of value to the community so they may be more easily found.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

How to add a Delete function to the Orders admin screen

Post by AbleMods » Sun Feb 17, 2008 10:00 pm

Advisory
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) ;)

This modification assumes AC7 RC2.

Introduction
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.

Modifications
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:

Code: Select all

                                <asp:DropDownList ID="BatchAction" runat="server">
                                    <asp:ListItem Text=""></asp:ListItem>
                                    <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>
                                    <asp:ListItem Text="-----------"></asp:ListItem>
Directly below the first "------------" ListItem entry you see, add this code:

Code: Select all

                                    <asp:ListItem Text="* DELETE *" Value="DELETE"></asp:ListItem>
                                    <asp:ListItem Text="-----------"></asp:ListItem>
Save it.

Now edit the ~/Admin/Orders/Default.aspx.cs file. Find the code located in the BatchButton_Click function that looks like this:

Code: Select all

                    case "SHIPOPT":
                        Response.Redirect("Batch/Ship.aspx?orders=" + GetOrderList(orderIds));
                        break;
We need to Insert another CASE section of code like this directly below the "break;" line. So add the following code as described:

Code: Select all

                    case "DELETE":
                        int DelCount = 0;
                        foreach (int orderId in orderIds)
                        {
                            Order order = OrderDataSource.Load(orderId);
                            if (order != null)
                            {
                                order.Delete();
                                messages.Add("Order #" + order.OrderId + " deleted.");
                                DelCount++;
                            }
                        }
                        messages.Add(DelCount + " orders deleted.");
                        break;

Save it.

Testing
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.

Cascade Deletes
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.

Conclusion
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.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

sweeperq
Commodore (COMO)
Commodore (COMO)
Posts: 497
Joined: Tue Jan 03, 2006 2:45 pm

Post by sweeperq » Mon Feb 18, 2008 7:05 am

Is there a reason you wouldn't just cancel the order instead?

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Post by AbleMods » Mon Feb 18, 2008 7:17 am

of course, but cancelled orders never leave the list or the customer order history.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
batmike
Commander (CMDR)
Commander (CMDR)
Posts: 123
Joined: Tue Sep 04, 2007 10:46 am
Location: Minneapolis, MN
Contact:

Post by batmike » Mon Feb 18, 2008 12:58 pm

Works great for me ... and helps keep things clean and neat. Thanks!

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Post by compunerdy » Thu Feb 21, 2008 10:13 am

Works great..I hope able is going to include some of these nice add ons with future releases so we dont have to manually change them after each update.

User avatar
Hostmaster
Commander (CMDR)
Commander (CMDR)
Posts: 126
Joined: Fri Jan 04, 2008 3:30 pm
Location: Melbourne Fl
Contact:

Post by Hostmaster » Fri Feb 22, 2008 1:23 pm

Joe another great add on by you.
I actually placed " ** DELETE Permanently No Undo: Print First " as the list Item text. That way the end user, my client, can’t yell when he deletes something good and doesn’t have a copy :D

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: How to add a Delete function to the Orders admin screen

Post by compunerdy » Sun May 11, 2008 12:58 am

Does this do a restock?

TTMedia
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 83
Joined: Mon Dec 03, 2007 11:49 am

Re: How to add a Delete function to the Orders admin screen

Post by TTMedia » Fri Nov 28, 2008 1:25 pm

BUmp.. does this do a restock?

I assume it doesn't matter because stock is only pulled when the order is put to ship.. and at that point, it's too late to cancel/delete the order.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: How to add a Delete function to the Orders admin screen

Post by AbleMods » Fri Nov 28, 2008 9:03 pm

Dunno. Test it and see what it does. I don't maintain my own inventory figures.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

tosypian
Ensign (ENS)
Ensign (ENS)
Posts: 9
Joined: Mon Aug 11, 2008 9:41 am
Location: Tampa, FL
Contact:

Re: How to add a Delete function to the Orders admin screen

Post by tosypian » Wed Feb 25, 2009 5:28 pm

Does this work as is on the latest version of AC7?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How to add a Delete function to the Orders admin screen

Post by mazhar » Thu Feb 26, 2009 5:45 am

Yes it will work.

User avatar
robrbecker
Ensign (ENS)
Ensign (ENS)
Posts: 1
Joined: Thu Jun 04, 2009 12:59 pm

Re: How to add a Delete function to the Orders admin screen

Post by robrbecker » Thu Jun 11, 2009 9:16 am

You can add a delete confirmation dialog easily.

In Admin\Orders\Default.aspx add an OnClientClick attribute to the button so it looks like:

Code: Select all

<asp:Button ID="BatchButton" runat="server" Text="GO" OnClick="BatchButton_Click" OnClientClick="if ($('ctl00_MainContent_BatchAction').value == 'DELETE') return confirm('Are  you sure you want to delete this order? It will be totally and permanently gone!');"/>

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: How to add a Delete function to the Orders admin screen

Post by ZLA » Thu Jun 11, 2009 11:58 am

As a less permanent delete function, I would recommend the following if you are decent at SQL:
[*]Create copies of all order table schemas. For example del_Orders, del_OrderItems, etc.
[*]Modify the schemas to remove identity from any columns but leave them as primary keys.
[*]Create a delete trigger on ac_Orders that copies that order's data from ac_Orders to del_Orders, ac_OrderItems to del_OrderItems, etc. If necessary, you could build something which would iterate through sysColumns to build the copy statements dynamically in case you have customized and added columns to any of these core tables.

You could also modify the schemas and add DeleteId, DeletedOn, DeletedBy columns if you need type of info as well.

Now if you ever need that data you can look it up via your favorite database tool. Or go one better and create an undelete function which reinserts these records into the main table using SET IDENTITY OFF.

jasonhendee
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 42
Joined: Fri Apr 15, 2011 11:04 pm

Re: How to add a Delete function to the Orders admin screen

Post by jasonhendee » Thu May 12, 2011 3:45 pm

Very cool, and much needed mod - Thanks!
Jason Hendee
Cables for Less

Post Reply