Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', 1);
  4. require('app/Mage.php');
  5. umask(0);
  6.  
  7. Mage::app();
  8.  
  9. /* tell the browser that we are a csv file */
  10. header("Content-type: text/csv");
  11. header("Content-Disposition: attachment; filename=orders.csv");
  12. header("Pragma: no-cache");
  13. header("Expires: 0");
  14.  
  15. /* Set our dates */
  16. $fromDate = '2016-05-20 00:00:00';
  17. $toDate = '2019-01-01 00:00:00';
  18.  
  19. /* Get the collection. Here we set a date range, and ignore cancelled orders.
  20. You can filter the collection however you prefer */
  21. $orders = Mage::getModel('sales/order')->getCollection()
  22. ->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
  23. ->addFieldToFilter('status', array('nin' => array('canceled')));
  24.  
  25. /* Here you can build an array, print to screen, write to a CSV etc */
  26. echo "Order ID,Customer Name,Order Total".PHP_EOL;
  27. foreach($orders as $o){
  28.  
  29. /* lets output the required data in csv format */
  30. echo $o->getIncrementId().',';
  31. echo $o->getCustomerName().',';
  32. echo $o->getBaseGrandTotal();
  33. echo PHP_EOL;
  34.  
  35. /* you can load the order items, if you need them */
  36. //$items = $order->getAllVisibleItems();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement