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

  • Create orderExport.php on magento root directory and add this code and run the file in browser. – Purushotam Sharma Jan 16 '18 at 4:37
  • Please accept my answer if it is helpful to you – Jigs Parmar Jan 18 '18 at 5:07
    $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



    $fp = fopen('exports_order.csv', 'w+');
    $csvHeader = array('ID','STATUS');
    fputcsv( $fp, $csvHeader,",");
    foreach($data as $row)
        fputcsv($fp, array($row->getId(),$row->getStatus()), ",");
  • where should i use this script – Sajjad Jan 17 '18 at 4:48
  • create test.php file in root – Jigs Parmar Jan 17 '18 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 Jan 17 '18 at 4:54
  • i have file orderExport.php with the above code – Sajjad Jan 17 '18 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 – Jigs Parmar Jan 17 '18 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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