Thursday, 22 August 2013

Getting products from an order in Magento

Getting products from an order in Magento

In my magento project, under My Account > My Orders (logged on customer),
I am able to view the order details along with the products I ordered.
Now, for each of the ordered product, I'd like to retrieve a specific
attribute however, from my understanding, the code snippet at the
beginning of sales/order/items/renderer/default.phtml which is $_item =
$this->getItem(); is the order itself so if I use something like
$_item->getId(), I'm getting the order id and not the product's.
I tried researching and ended up with this code:
$orders = Mage::getModel('sales/order')->load($_item->getId());
foreach($orders as $order):
$is = $order->getAllItems();
foreach($is as $i):
echo $i->getProductId();
endforeach;
endforeach;
Hoping I could use the product id to get the other attributes of the said
product however, I 'm getting an error with this code with no way of
telling what the error is. I've also tried something like this:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('name', $name);
foreach($_productCollection as $_product):
$_temp =
$_product->getResource()->getAttribute('name_en')->getFrontend()->getValue($_product);
endforeach;
But I keep getting 0 when I try to check the count of items in the product
collection. How can I retrieve a custom attribute for the product in this
page?

No comments:

Post a Comment