Magento is a Feature pack CMS when it comes to E-commerce solution with a rich inventory management system, but still, sometimes Magento step back when it comes to a real-world problem which saves time and efforts both. Exporting Sales Order Customer Data is daily and necessary for store owners who manage warehouse as well as shipment of product by sending data to the shipment service provider. Recently, we want to export Magento Sales Order Customer Data for a store which has a large amount of database but Unfortunately, Magento has the only capability to export customer and product data only.
Within a short period of time, we came out with a small script, which helped us to export sales order data to CSV file. With the script, one can also add or remove export field as per the need for generating a custom report. So, today we are again back with an article that will help you to Export Magento Sales Order Customer Data to Excel File Programmatically.
All you need to do is create a file with below code and named it as “ExportOrder.php“.
$fp = fopen('exports_order.csv', 'w+');
$csvHeader = array('ORDER ID','CUSTOMER FIRST NAME','CUSTOMER LAST NAME','CUSTOMER EMAIL','SHIPPING METHOD','ORDER DATE','STATUS');
fputcsv( $fp, $csvHeader,",");
foreach($data as $row)
fputcsv($fp, array($row->getId(),$row->getCustomerFirstname(),$row->getCustomerLastname(),$row->getCustomerEmail(),$row->getShippingDescription(),$row->getCreatedAt(),$row->getStatus()), ",");
echo 'exports_order.csv File Generated Successfully.';
Once the file is created copy it to the root directory of your server and hit the file URL. It will automatically generate “exports_order.csv” file in the root directory.
You can customize this code according to your need by adding or removing fields. Don’t forget to smash the stars if this code work for you and comment down below if you need any help regarding this code.