Magento get items in order

December 27, 2011 | In: Magento

Here, I can show you how you can get information about all items in your magento shopping cart based on order id. How to get product details from order id or sometimes need to get product it, product sku, product name , category id, category name. So its easy to get product from order item based on order number.

<?php
require 'app/Mage.php';
Mage::app();

$orderNumber = 100004544;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
// get order total value
$orderValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = '');
// get order item collection
$orderItems = $order->getItemsCollection();

foreach ($orderItems as $item){

	$product_id = $item->product_id;
	$product_sku = $item->sku;
	$product_name = $item->getName();
	$_product = Mage::getModel('catalog/product')->load($product_id);
	$cats = $_product->getCategoryIds();
	$category_id = $cats[0]; // just grab the first id
	$category = Mage::getModel('catalog/category')->load($category_id);
	$category_name = $category->getName();

	echo "orderNumber=".$orderNumber."<br/>";
	echo "orderValue=".$orderValue."<br/>";
	echo "product_name=".$product_name."<br/>";
	echo "product_id=".$product_id."<br/>";
	echo "product_sku=".$product_sku."<br/>";
	echo "category_id=".$category_id."<br/>";
	echo "category_name=".$category_name."<br/><br/>";

}
?>

Comments

comments

Powered by Facebook Comments

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>