Pages

Tuesday, November 25, 2014

How to delete orders

Usually you have after a certain time of developing some test orders that you want go get rid of. this is a small script to delete them


// if you run this code in a shell, see comment below, you have to set this flag
Mage::register('isSecureArea', true);

// select all orders
$orders = Mage::getModel('sales/order')->getCollection();

// select defined orders listed in $orderIds  
$orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('entity_id', (array) $orderIds);

foreach ($orders as $order) { 
    $order->delete(); 
}

you can run code snippet like above with a php shell as provided in Magento PHP Developer's Guide (p.58)

No comments:

Post a Comment