Magento 1.7 – Get Custom Attribute Value in Observer

attributescheckoutevent-observermagento-1.7

I have created a module which uses a Observer for the event 'checkout_onepage_controller_success_action'

I need to get the list of items in the order and get a custom attribute (the type is text).

So far I can load the order and get all items in that order:

$orderIds = $observer->getEvent()->getOrderIds();
$order = Mage::getModel('sales/order')->load($orderIds);
$ordered_items = $order->getAllItems();

So far to get some of the attributes for each item in the order I do this:

foreach ($ordered_items as $item) {
    echo $item->getName()."<br />";
    echo $item->getSku();
}

These values are displaying fine. The problem is each product has a custom attribute with the code 'isbn_10' but I can't get the value to display. Some code I've tried is:

$item->getAttributeText('isbn_10');
$item->getIsbn10();
$item->getResource()->getAttribute('isbn_10')->getFrontend()->getValue($item);

Any help is much appreciated. Thanks.

Best Answer

Try with

$item->getProduct()->getAttributeText('isbn_10');

or

$product = Mage::getModel('catalog/product')->load($item->getProductId())->getAttributeText('isbn_10');

or

$product = Mage::getModel('catalog/product')->load($item->getProductId())->getData('isbn_10');
Related Topic