Reputation: 89
I'm new to Magento. I'm trying to list some order details (after the purchase has been made). I'm trying the following code to get the whole amount of order, product id and order id. But this doesn't give the expected results. Any ideas how to rewrite this to work?
$collection = Mage::getModel('sales/order')->getCollection();
foreach($collection as $order) {
$id = $order->getIncrementId();
$amount = $order->getFinalPrice();
$product_id = $order->getSku();
echo $id;
echo $amount;
echo $product_id;
}
Upvotes: 1
Views: 114
Reputation: 630
You're on the right road:
$collection = Mage::getModel('sales/order')->getCollection();
foreach ($collection as $order){
$increment_id = $order->getIncrementId();
echo $increment_id . ":<br/>";
$ordered_items = $order->getAllItems();
foreach ($ordered_items as $item){
echo $item->getSku() . " @ " . $item->getPrice() . "<br/>";
}
}
The reason being, the sales/order
model fetches it's info from the sales_flat_order
table, whereas the items (sales/order_item
) fetch their information from sales_flat_order_item
.
Upvotes: 1