Sunday, March 10, 2013

Magento : How to get product custom option value programmatically

Magento has the power to define product variations (custom options) with each product, which allow your online customers to select an specific product from wide range of option available with each product,
Custom options are a good solution if your inventory needs are simple and you have a limited number of available SKUs.

get-product-custom-option-value
[php]
$product = Mage::getModel("catalog/product")->load(1); //product id 1
$i = 1;
echo "<pre>";
foreach ($product->getOptions() as $o) {
echo "<strong>Custom Option:" . $i . "</strong><br/>";
echo "Custom Option TITLE: " . $o->getTitle() . "<br/>"; //Colors
echo "Custom Option TYPE: " . $o->getType() . "<br/>"; //drop_down
echo "Custom Option Values: <br/>";
$values = $o->getValues();
foreach ($values as $v) {
print_r($v->getData());
}
$i++;
echo "<br/>";
}
[/php]

Hope It helps.
Happy coding

7 comments:

  1. Glad it helpd :-)

    ReplyDelete
  2. hi... in which file should add this code

    ReplyDelete
  3. am new to magento... so please guide me like above code in which file and where have to add...


    Thanks

    ReplyDelete
  4. For practice you can put a file in the root folder use this code :

    require_once('app/Mage.php');

    Mage::default('admin');

    //put the posted code here save and place this file on the root

    ReplyDelete
  5. thanks!!! really good job!

    ReplyDelete
  6. nice really working thanks for this post this is really helpfull

    ReplyDelete