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();      

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


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) {

  • 1
    not working... When i print the array $prodct all the information is being shown except the custom options while the same code is working fine in product view page – Shivika Sharma Feb 6 '16 at 9:43

The problem is that the product is not fully loaded in your block. The load() method makes sure that all information of an object is loaded. If you only use loadByAttribute() or a collection, this is not the case.

An example would be:

$product = Mage::getModel('catalog/product')->load($productId);

If you want to display multiple products, you should avoid using load() though as it has a strong negative performance impact. Sorry that I can't help you with adding options to a collection.

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.