.

.

Get All Custom Options of Particular Product by Product Id in magento



Getting the list of Custom Options of any Product programmatically, so that it can be stored in a variable or it can be shown in some non-product template file.
Let’s see example:-

<?php
require_once '../app/Mage.php';
Mage::app();
//header("Content-Type: application/json");
?>
<?php

 $prodid=502;
 $productCollection = Mage::getModel("catalog/product")->load($prodid);
 $i = 1;
  foreach ($productCollection->getOptions() as $value)
   {
   echo "<strong>Custom Option:" . $i . "</strong><br/>";
   echo "Custom Option TYPE: " . $value->getType() . "<br/>";
   $type = $value->getType();
   echo "Custom Option TITLE: " . $value->getTitle() . "<br/>";
   $title= $value->getTitle();
    echo "Custom Option Values: <br/>"; // Getting Values if it has option values, case of select,dropdown,radio,multiselect
    $values = $value->getValues();
   
    $j=0;
     foreach ($values as $values)
      {
     //print_r($values->getData());
     $valu[$j]=$values->getData();
   
     $j++;
      }
     
      $customoptionlist[$i]=array("type"=>$type,"title"=>$title,"value"=>$valu);
     
      $i++;
      }
   
     $data['responseCode']="1";
     $data['msg']="successful";
     $data['result']=$customoptionlist;
     $data2 = json_encode($data);
echo $data2;
     
   
      ?>






 


EmoticonEmoticon