0

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.

1

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');
  • Hi Marius, I've tried these two methods but both are still not displaying anything. Any other suggestions? – thairish Nov 29 '13 at 11:06
  • @xx0f. I added an other suggestion. If that does not work, I'm out of ideas. – Marius Nov 29 '13 at 11:44
  • The last one worked, many thanks for your help. – thairish Nov 29 '13 at 11:54
  • I have been playing with Magento custom Attributes for last one year and I figured out a safest way to get custom attribute value. Here is the detailed tutorial scriptbaker.com/get-custom-attribute-value-in-magento – Tahir Yasin Jun 22 '14 at 19:15
0

To add to this question am trying to add a column inside the invoice file now by editing the following file I managed to get an output but I struggle with the correct value from the database:

/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php

    //draw Pick Location
    $lines[0][] = array(
        'text'  => Mage::helper('core/string')->str_split($this->getPickLocationValue($item), 25),
        'feed'  => 280,
        'align' => 'right'
    );

and the function that seems to be the most important:

/*
 * Return Value of custom attribute
 * */
private function getPickLocationValue($item)
{
    $product = Mage::getModel('catalog/product')->load($item->getProductId())->getAttributeText('picklocation');

    if(!($return_location = $item->getPickLocation()))
        return 'N/A';
    else
        return $return_location;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.