Get data from sales order and sales order item in magento

I am working on a magento phent code to get customer name, email, product description, sku code, order number and customer id. However, I am a bit stuck trying to join the "sales / order" and "sales / order_item" models to print the data through a foreach loop and also get the current date only. This is what I got so far:

<?php
set_time_limit(0);
require_once '../app/Mage.php';
Mage::app('uk');
$collection = Mage::getModel('sales/order')
    ->getCollection()
    ->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
    ->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
    ->addAttributeToSelect('*')
    ->addAttributeToSort('created_at','DESC');
foreach ($collection as $c) {
    echo $c->getCustomerName() . "\t" .
    $c->getCustomerEmail() . "\t" .
    $c->getCreatedAt() . "\r\n";
}
?>

      

Could you give me a hand with this?

Many thanks,

Nestor

+3


source to share


1 answer


try under code



foreach ($collection as $c) {
	$order = Mage::getModel("sales/order")->load($c->getId());
	$ordered_items = $order->getAllItems();
	foreach($ordered_items as $item){
		 echo $item->getItemId(); 
		 echo $item->getSku(); -
	}
    echo $c->getCustomerName() . "\t" .
    $c->getCustomerEmail() . "\t" .
    $c->getCreatedAt() . "\r\n";
}
      

Run code


+4


source







All Articles