LinkedIn Twitter RSS Reset

Getting Ordered Items and their Detail from Order ID in Magento

Here is a small snippet of code, yet useful, to get ordered items and its details. I’ve deviced this code a lot before and posted in Magento Commerce’s Forum as well. But felt like writting it again, so that I can have a quick refrence to it as well. Next thing, I’ve tried a lot to get all orders and their items details by single query, but have not yet come up with a solution. If you have any method of finding order and its details by a single query, then please do response. The code below first needs an order ID as it parameters to give order details.

$order = Mage::getModel('sales/order')->load($order_id);
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId => $item)
{
	$name[] = $item->getName();
	$unitPrice[]=$item->getPrice();
	$sku[]=$item->getSku();
	$ids[]=$item->getProductId();
	$qty[]=$item->getQtyToInvoice();
}

Hope this might “just” help somebody in need.

15 Responses to “Getting Ordered Items and their Detail from Order ID in Magento”

  1. March 11, 2010 at 2:51 am #

    That’s a really useful tip, thanks.

  2. October 7, 2010 at 1:51 pm #

    Hi, really useful stuff! I am writing an order export module for magento and this is really good.

    Also, just posted a list of order and order item properties on my blog which may be useful to people…

    http://www.jimcode.org/2010/10/magento-order-product-properties

  3. October 26, 2010 at 10:11 am #

    how can i print to screen all of this?

  4. December 4, 2010 at 1:31 pm #

    It was very helpful to me to get the order details (Item, SKU, quantity).

    And i would like to mention the order id is an entity_id of the table sales_flat_order. Actually i first messed up with passing realOrderId (An order increment id) as an argument for

    $order_id = $_shipment->getRealOrderId()
    $order = Mage::getModel(‘sales/order’)->load($order_id);

    [Since am customizing a Shipment email template in email/order/shipment/items.phtml]

    but then i ran a raw SQL query to get an Orderid from the real order id and got my shipment details.

    SELECT entity_id
    FROM {$table_prefix}sales_flat_order
    WHERE increment_id = $real_order_id

    BTW, Your blog has a pretty useful articles, besides good articles in Magento, i would like to appreciate for this nice work and have subscribed to your blog.

    Hope i can learn more from your Blog. Thank you once again !

  5. Lalit
    January 15, 2011 at 7:10 am #

    Thanks Its working for me.

  6. February 14, 2011 at 9:10 pm #

    Thank you so much, I could not figure out how to load these!

    You saved me hours! Thanks again and keep the posts coming!

  7. PonnuKumar
    February 15, 2011 at 9:49 am #

    Thanks a lot for you code ,but the provided code is working only for simple products.In case of configurable products repetition arises Can you let me know how it should be implemented in case of configurable products and bundle products

  8. Vijay
    September 8, 2011 at 7:51 pm #

    Good One, Thank you

  9. Nauman
    September 16, 2011 at 11:51 am #

    thanks for posting this very useful piece of code.

    Can you please further guide on how to get the ordered items attributes?

  10. September 22, 2011 at 8:55 am #

    Thank You

  11. deni
    September 29, 2011 at 7:45 pm #

    There is a problem with the code. If the Item Status of the produtcs is Mixed the getQtyToInvoice() returns 0. I’m using magento 1.4.2. Any fix on this?

    • November 16, 2011 at 10:34 am #

      @deni: Use $orderItem->getQtyInvoiced();

  12. January 13, 2012 at 12:19 am #

    Thanks all of your articles.
    In the above code I have the following errors when execute from external php:
    Call to a member function getAllItems()

    I’m using 1.4.1.1
    Is there any change in the code to work with this version?

  13. zard
    March 16, 2012 at 9:20 pm #

    Hi,

    Thanks for your code, it helped me for magento CE 1.5.1.

Trackbacks/Pingbacks

  1. Mendapatkan Detail Order di Magento « just tango on - August 19, 2011

    [...] Dapet dari sini http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/ [...]

Leave a Comment