Posted By

hotdiggity on 02/23/11


Tagged

cron magento


Versions (?)

Delete cancelled magento orders cron


 / Published in: PHP
 

URL: http://www.magentocommerce.com/boards/vie/viewthread/2960/#t259879

Say you don’t want to reset ALL your orders, maybe you want to PRUNE a production database. if that’s the case, this php file (added to a crontab, or ran from your magento root directory) will DELETE all cancelled orders (5000 limit per instance). This is helpful for production instances, to keep your magento running smoothly if you run alot of test transactions.

  1. <?php
  2.  
  3. require_once('app/Mage.php');
  4. Mage::app('admin');
  5. Mage::getSingleton("core/session", array("name" => "adminhtml"));
  6. Mage::register('isSecureArea',true);
  7. $collection = Mage::getResourceModel('sales/order_collection')
  8. ->addAttributeToSelect('*')
  9. ->setPageSize(5000)
  10. ->addFieldToFilter('status', 'canceled')->load();
  11.  
  12. foreach ($collection as $col) {
  13. Mage::log($col->getIncrementId() . ' order deleted ');
  14. try {
  15. $col->delete();
  16. } catch (Exception $e) {
  17. throw $e;
  18. }
  19. }

Report this snippet  

You need to login to post a comment.