Magento – $product->getOptions() returns empty result

custom blockcustom-optionsmagento-1.9product

I am trying to get product details including product custom options value in a custom block i created.This is the code i used on product detail page and it worked there, but when trying to use it on custom block page get Options returns empty value.

if ($_product->getId()) {  
    foreach ($_product->getOptions() as $opt) {  
    echo  $optionType = $opt->getType();  
      if ($optionType == 'drop_down') {  
        $values = $opt->getValues();  
        foreach($values as $v)
        {
     $mydata = $v->getTitle();      
print_r($mydata);    
        }
      }  
    }   
}

I am new to magento so not sure what i am missing out here.
Can any one give me a hint please
Thanks

Best Answer

Try this:

if (Mage::registry('current_product')) {
    $product = Mage::registry('current_product');
} else {
    $product = Mage::getSingleton('catalog/product');
}


if ($product->getId()) {
    if ($product->hasCustomOptions()) {
        foreach ($product->getOptions() as $option) {
            $optionType = $option->getType();
            if ($optionType == 'drop_down') {
                $values = $option->getValues();
                foreach ($values as $k => $value) {
                    print_r($value);
                }
            }

        }
    }
}
Related Topic