Deleting Orders in Magento
Posted on October 13, 2012 by Nimrod Techn There have been 0 comments
Usually there's no need to remove orders in Magento. legally-speaking, it is also not recommended.
However, sometimes we would like to delete test orders, especially in the very early stages of the website development.
After Googling for awhile, I found out that some people recommend using the following method in order to delete orders from Magento:
Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
However, this is far from being the best of practices, and is by no means a proper solution. the order will still be displayed in the order grid (admin panel), just everytime you try to view to order details you will get the following error:
"This order no longer exists"
That's because there are still references to the order in other DB tables.
The related entity ID's have to be removed from the following tables:
log_quote
sales_flat_order
sales_flat_order_address
sales_flat_order_item
sales_flat_order_payment
sales_flat_order_status_history
sales_flat_order_grid
sales_flat_invoice_comment
sales_flat_invoice_item
sales_flat_invoice
sales_flat_invoice_grid
sales_flat_quote_address_item
sales_flat_quote_item_option
sales_flat_quote
sales_flat_quote_address
sales_flat_quote_item
sales_flat_quote_payment
sales_flat_creditmemo_comment
sales_flat_creditmemo_item
sales_flat_creditmemo
sales_flat_creditmemo_grid
sales_flat_shipment_comment
sales_flat_shipment_item
sales_flat_shipment_track
sales_flat_shipment
sales_flat_shipment_grid
Soon enough I will release an extension that removes the orders automatically and will spare you the manual work.
This post was posted in Core