Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to fetch the custom options and their sub options of any product?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 666
    Comment on it

    In magento if we need to get the custom options and their sub options of any product we need to write a query and from that result we can extract the options.

     

    Lets see how can we do it:

     

    Firstly, load the product from the catalog/product model with product id as:

     

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

     

    Now we have that product. To fetch the options collection from the product we will use the method getProductOptionCollection(), from the model 'catalog/product_option'.

     

     $options = Mage::getModel('catalog/product_option')->getProductOptionCollection($_item);

     

    In the above query we have passed the product as parameter to function getProductOptionCollection(). Now, we have the list of custom options lets print them, for that follow the below code.

     

    if(!empty($options))
    {
         foreach ($options as  $option)
           {
            echo "Option :".$option->getDefaultTitle()."\n";
            echo "Values:\n";
    
               foreach ($option->getValues() as  $value)
               {
               print_r($value->getData());
               }
            }
     }

     

    In the above code in foreach loop we have getDefaultTitle() method to fetch the option title and then in another nested loop printed each values of option.


    In this way we can fetch the custom options of any product and perform any optrations on them.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: