Magento Getting all custom options from product by product id

Magento Getting all custom options from product by product id

In this post we will show you Magento Getting all custom options from product by product id, hear for Magento Getting all custom options from product by product id we will give you demo and example for implement.

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 an example for the custom option. Suppose you have a product say cloth ,So you need to give the user to select what type of cloths they wants. we 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:

Getting Values if it has option values, case of select, dropdown, radio, multiselect
Getting Values if it has option values, case of select, dropdown, radio, multiselect

The code below is to get the all the custom options of a product. Here we fetching the custom attributes of the products which have the product Id 116.

$productId = 116; //add your product Id
$productCollection = Mage::getModel("catalog/product")->load($productId);
$count = 1;
// Getting all custom options
foreach ($productCollection->getOptions() as $value) 
{
	echo "<strong>Custom Option:" . $count . "</strong><br/>";
	echo "TYPE of Custom Option : " . $value->getType() . "<br/>";
	echo "TITLE of Custom Option : " . $value->getTitle() . "<br/>";
	echo "Values of Custom Option : <br/>";
	// hear we are Getting Values if it has option values, case of select, dropdown, radio, multiselect
	$values_option = $value->getValues();
	foreach ($values_option as $value_option) 
	{
		print_r($value_option->getData());
	}
	$count++;
}

Hope this code and post will helped you for implement Magento Getting all custom options from product by product id. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

5  +  4  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US