So I have this script:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require('app/Mage.php');
umask(0);
Mage::app();
/* tell the browser that we are a csv file */
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=orders.csv");
header("Pragma: no-cache");
header("Expires: 0");
/* Set our dates */
$fromDate = '2016-05-20 00:00:00';
$toDate = '2019-01-01 00:00:00';
/* Get the collection. Here we set a date range, and ignore cancelled orders.
You can filter the collection however you prefer */
$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
->addFieldToFilter('status', array('nin' => array('canceled')));
/* Here you can build an array, print to screen, write to a CSV etc */
echo "Order ID,Customer Name,Order Total".PHP_EOL;
foreach($orders as $o){
/* lets output the required data in csv format */
echo $o->getIncrementId().',';
echo $o->getCustomerName().',';
echo $o->getBaseGrandTotal();
echo PHP_EOL;
/* you can load the order items, if you need them */
//$items = $order->getAllVisibleItems();
}
I want to get the sku, products ordered, quantity ordered. How can I do that?