2

I try to get the products which have been bought. This is my code:

    /** @var $order Mage_Sales_Model_Order */
    $order = $eventObserver->getOrder();

    /** @var $items Mage_Sales_Model_Resource_Order_Collection */
    $items = $order->getItemsCollection(array(), TRUE);

    /** @var $item Mage_Sales_Model_Order_Item */
    foreach($items as $item) {
        $product = $item->getProduct();
        var_dump($product->getData('language'));
    }

Language is a custom attribute. In this case it is empty, and I have no idea why. All default attributes, like name, id or sku are working.

This language is used as configurable attribute.

What have I to do, to get the value?

4
  • 1
    What is the input type of the attribute? Is it Text Field, Text Area,Date, Yes/No, Multiple Select or Dropdown?
    – ceckoslab
    Sep 6, 2012 at 10:58
  • It is a multiple select.
    – Armin
    Sep 6, 2012 at 12:06
  • 1
    Do you get some data if you use: $product->getAttributeText('language') ?
    – ceckoslab
    Sep 6, 2012 at 12:13
  • This returns FALSE. But when I use $product->getAttributes() the language attribute (and the other custom attributes, which are empty) are listed.
    – Armin
    Sep 6, 2012 at 13:57

2 Answers 2

0

Try this:

$items = $order->getAllVisibleItems()
1
  • When I use this, I get just the configurable products (okay, that makes sense, they the visible ones). But the configurable products doesn't contain the language. So I need to get the simple product, which has been ordered.
    – Armin
    Sep 6, 2012 at 13:55
0

Got it! When I take the product ID and load the product again:

$product = $item->getProduct();
$product = Mage::getModel('catalog/product')->load( $product->getId() );

I get the language as number.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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