I'm new on Magento.
How to export orders with code SKU price etc.
I read the link below but didn't get where to add this code and how this code works please help.
Programmatically Export Sales order customer details to excel format
I'm new on Magento.
How to export orders with code SKU price etc.
I read the link below but didn't get where to add this code and how this code works please help.
Programmatically Export Sales order customer details to excel format
<?php
require_once("app/Mage.php");
Mage::app();
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$orders = Mage::getModel('sales/order')->getCollection();
$orders->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE);
$fp = fopen('export.csv', 'w');
$header = array("Customer ID", "First Name", "Last Name", "Email", "City", "Telephone", "Country", "Postcode", "Status");
fputcsv($fp, $header);
foreach($orders as $order) {
$billingAddress = $order->getBillingAddress();
$countryCode = $billingAddress->getCountryId();
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
$countryName = $country->getName();
$fields = array($order->getId(), $billingAddress->getFirstname(),$billingAddress->getLastname(), $billingAddress->getEmail(), $billingAddress->getCity(), $billingAddress->getTelephone(), $countryName, $billingAddress->getPostcode(), $order->getStatus());
fputcsv($fp, $fields);
}
?>
Please try this, Its working for me
You can use below script to export order
<?php
require_once('app/Mage.php');
Mage::app();
$data=Mage::getModel('sales/order')->getCollection();
$fp = fopen('exports_order.csv', 'w+');
$csvHeader = array('ID','STATUS');
fputcsv( $fp, $csvHeader,",");
foreach($data as $row)
{
fputcsv($fp, array($row->getId(),$row->getStatus()), ",");
}
fclose($fp);
?>