Magento – Get product custom option value

custom-optionsmagento-1.8

I have added a quantity field as per http://hkpatel201.blogspot.co.uk/2014/03/how-to-add-custom-qty-to-custom-option.html

All is working well. Screenshot of the admin is http://snag.gy/H9zE4.jpg

I know the following code gets me the Option Type ID

$orderItemOptions = $orderItem->getProductOptions();                            
if (isset($orderItemOptions['options'][0]['option_value']))
{
    $selectedOrderItemOptionId = $orderItemOptions['options'][0]['option_value'];
}

But my question is how do I get the Option Type based on the ID?

Best Answer

Try

foreach ($orderItem->getProductOptions() as $opt) {  
  $optionType = $opt->getType();  

  echo 'Type : '  . $optionType;
} 

To load option by id

$id = 9;
$opt = Mage::getModel('catalog/product_option')->load($id); 
$opt->getType();

From your code above

$opt = $orderItemOptions['options'][0];
$optionType = $opt->getType();
Related Topic