I want to get the product custom attribute value for all the products in each order. How can i get the product attribute value using both order id and product id in magento 1.9

| improve this question | | | | |

You can get it from $order object as shown below

foreach ($order->getAllItems() as $item) {
    // get all custom options for the order item
        $customOptions = $item->getProductOptions();

        foreach ($customOptions['options'] as $_individualOption) {
        /* You will get information about all the custom options
            $_individualOption['option_value'] will show the value id of dropdown item selected*/
        /* Although if you wanna show the value title instead of id, you could simply create a method to get it*/
        $optionValueTitle = $this->getCustomOptionTitle($_individualOption['option_id'], $_individualOption['option_value']);

You can write a method to get title of selected option value as below

public function getCustomOptionTitle($optionId, $valueId)
    $option = Mage::getModel('catalog/product_option')->load($optionId);
    if ($option->getType() === 'drop_down') {
        $values = Mage::getSingleton('catalog/product_option_value')->getValuesCollection($option);
        foreach ($values as $value) {
                return $value['title'];
    return null;

Note: I didn't get time to run and verify the output, so kindly check for any typo/syntactic error. But the overall logic should not change. Also the getCustomOptionTitle() will only work for option type drop_down. so make sure to handle exceptions for other input types.

| improve this answer | | | | |

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.