How Can I Export Magento Sales Order Customer Info Programmatically

I would like to export Magento Sales Order Customer info programmatically, what functions or methods should I use and what steps should I do to export the Magento sales order customer info programmatically

You need to retrieve the Magento sales orders first (with attribute filter if need), then call fputcsv to save data into excel format file

Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$orders = Mage::getModel('sales/order')->getCollection();
$orders->addAttributeToFilter('grand_total', array('gt' => '10.00'));
$fp = fopen('path/exportfile.csv', 'w');
if(count($orders) > 0){
    foreach($orders as $order) {
        $countryCode = $order->getBillingAddress()->getCountryId();
        $country = Mage::getModel('directory/country')->loadByCode($countryCode);
        $countryName = $country->getName();
        $fields = array($order->getId(), $order->getBillingAddress()->getFirstname(),$order->getBillingAddress()->getLastname(), $order->getBillingAddress()->getEmail(), $order->getBillingAddress()->getCity(),  $order->getBillingAddress()->getTelephone(), $countryName, $order->getStatus());
        fputcsv($fp, $fields);
    }
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments