1

I would like to export the last 1000 orders with following fields: order id, customer email, first name, last name.

Is there an easy way to export a CSV like this? I do have access to PHPMyAdmin.

2

Here is the script to export last 1000 orders into csv format. To use this script just create test.php in your magento root directory and paste this code and run this script.

<?php
ini_set('display_errors', 1);
require_once('app/Mage.php');
Mage::app();

$orders = Mage::getModel('sales/order')->getCollection()
    ->setOrder('created_at', 'desc')
    ->setPageSize(1000); // from here you can update the order count
$fp = fopen(Mage::getBaseDir() . DS . "exports_order.csv", "w+");
$csvHeader = array('Order ID', 'Customer Email', 'Customer First Name', 'Customer Last Name');
fputcsv($fp, $csvHeader, ",");
foreach ($orders as $order) {
    fputcsv($fp, array(
        $order->getIncrementId(),
        $order->getCustomerEmail(),
        $order->getCustomerFirstname(),
        $order->getCustomerFirstname()
    ));
}
fclose($fp);

echo 'exports_order.csv Successfully created.';
exit;
2

Use "Export" function to export to CSV table sales_flat_order.

  • 1
    For some reason the sales_flat_order table is missing the last orders that I see in the backend. For example the last order in the BE is: 100002988 and the last entity_id in "sales_flat_orders" is 2772.. entity_id is the order ID right ? – user6800816 Jan 20 '18 at 20:30
  • 2
    entity_id is not the same thing as order number. entity_id is just database table index, autoincrement number, and increment_id is your "human" order number, both visible for customer and in admin panel. – A.Maksymiuk Jan 20 '18 at 20:38

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.