3

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

2
  • Create orderExport.php on magento root directory and add this code and run the file in browser. Commented Jan 16, 2018 at 4:37
  • Please accept my answer if it is helpful to you Commented Jan 18, 2018 at 5:07

2 Answers 2

2
<?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

0

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);
?>
10
  • where should i use this script
    – Sajjad
    Commented Jan 17, 2018 at 4:48
  • create test.php file in root Commented Jan 17, 2018 at 4:51
  • i didn't see any other information accept get mail or order i want complete order detail like sku price inventory
    – Sajjad
    Commented Jan 17, 2018 at 4:54
  • i have file orderExport.php with the above code
    – Sajjad
    Commented Jan 17, 2018 at 4:56
  • you change code as per your requirment , current code genrate exports_order.csv file in your root with order id and order status only Commented Jan 17, 2018 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.