Getting all custom options of a product in Magento



In Magento Custom options are the options that can be added to any products individually through the admin panel, which provides an option for the user to select what type of product they actually want. Here is a example for the custom option. Suppose you have a product say T-Shirt ,So you need to give the user to select what type of T-Shirts they wants. You can do it by using configurable product as well as by the Simple Product also.

For Creating the Custom Option of a simple products Select the products for which you want to create the Custom Options like the Color and Size Navigate to the Catalog –> Manage Products –> Select The Products from the Product Grid and Select Custom Options from the left menu (Extreme below) then click on the Add New Option Buttons on the Right Side. Refere the Screenshot below:

CustomOptions
The code below is to get the all the custom options of a product. Here I am fetching the custom attributes of the products which have the Id 100.

<?php
$productCollection = Mage::getModel("catalog/product")->load(100);
$i = 1;
foreach ($productCollection->getOptions() as $value) {
echo "<strong>Custom Option:" . $i . "</strong><br/>";
echo "Custom Option TYPE: " . $value->getType() . "<br/>";
echo "Custom Option TITLE: " . $value->getTitle() . "<br/>";
echo "Custom Option Values: <br/>";
// Getting Values if it has option values, case of select,dropdown,radio,multiselect
$values = $value->getValues();
foreach ($values as $values) {
print_r($values->getData());
}
$i++;
}
?>

Hope this will be helpful to someone. Enjoy and Happy Coding in Maganto