Magento get items in order

Home / Magento / Magento get items in order

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/>";

}
?>

Related Posts

4 Comments

  • Magento developers many times get confused for designing a website in a unique way. After visiting this article, one can easily get the overview of designing a particular Ecommerce website. As the matter of fact, various platforms require different kinds of designs for better engagement of a product. So after visiting here, one can easily get the best overview of designing a website.

  • Heya! I just wanted to ask if you ever have any problems with hackers?
    My last blog (wordpress) was hacked and I ended up losing many months of hard
    work due to no data backup. Do you have any solutions to
    stop hackers?

  • Hello! I know this is kinda off topic but I was wondering which blog platform are you using
    for this website? I’m getting fed up of WordPress because I’ve had issues with hackers and I’m looking at options for another platform.
    I would be awesome if you could point me in the direction of a good platform.

Leave a Reply

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