Hello I would like to obtain a csv file containing the list of products (Order ID, EAN code and quantity) present in the orders whose status is being processed. How to proceed ?

  • You can use order API or fetch order collection with filer "processing" state to get desired results
    – Mufaddal
    Apr 12, 2021 at 12:00

1 Answer 1


I found this code :

ini_set("memory_limit", "100000M");

require_once('app/Mage.php'); //Path to Magento

// Set an Admin Session
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$userModel = Mage::getModel('admin/user');
$session = Mage::getSingleton('admin/session');

$connection = Mage::getSingleton('core/resource')->getConnection('core_write');

$fromDate = date('Y-m-d H:i:s', strtotime('2018-01-01'));
$toDate = date('Y-m-d H:i:s', strtotime('2019-01-01'));

/* Get orders collection of pending orders, run a query */
$collection = Mage::getModel('sales/order')
//      ->addFieldToFilter('state',Array('eq'=>Mage_Sales_Model_Order::STATE_NEW))
    ->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
//    ->setPageSize(2)
//    ->setCurPage(1);

$data[0] = array(
    'Order ID',
    'Shipping description',
    'Grand Total',
    'Total Qty Ordered',
    'Customer First name',
    'Customer Last name',
    'Customer Email',
    'Created At',
    'Billing Company',
    'Billing Name',
    'Billing City',
    'Billing Street',
    'Billing POST Code',
    'Shipping Company',
    'Shipping Name',
    'Shipping City',
    'Shipping Street',
    'Shipping POST Code',
    'Item Name',
    'Qty Ordered',
    'Product SKU'

foreach ($collection as $order) {

    if ($billingAddress = $order->getBillingAddress()) {
        $billingStreet = $billingAddress->getStreet();
    if ($shippingAddress = $order->getShippingAddress()) {
        $shippingStreet = $shippingAddress->getStreet();

    $orderData = array(
        date('Y-m-d', strtotime($order->getCreatedAt())),


    foreach ($order->getAllItems() as $itemId => $item) {

        $item_name = str_replace('&', " ", $item->getName());
        $itemData = array(

        $data[] = array_merge($orderData, $itemData);


header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="productData.csv"');

$fp = fopen('php://output', 'wb');
foreach ($data as $line) {
    fputcsv($fp, $line, ',');

Your Answer

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

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