3

I have a virtual product and it consists with various types of custom options such as drop-downs, text fields, radio buttons etc. Once the place order clicks I'm firing an event observer. There I want to get the selected values of all these custom options.

How to achieve this? I can get the option titles. But can't get the selected values of them.

  • you mean ordered item option values? – saravanavelu Jul 10 '15 at 5:53
  • yes, i can get the order item and then the product. But i cannot get the custom option values (selected) of it – Sukeshini Jul 10 '15 at 6:01
  • check my answer – saravanavelu Jul 10 '15 at 6:22
2

Try the below code,

    $order = $observer->getEvent()->getOrder();
    $items = $order->getAllVisibleItems();
    foreach ($items as $item) {
    $options = $item->getProductOptions(); 
    $customOptions = $options['options'];   
    if(!empty($customOptions))
    {
      foreach ($customOptions as $option)
      {     
         $optionTitle = $option['label'];
         $optionId = $option['option_id'];
         $optionType = $option['type'];
         $optionValue = $option['value'];
      }
   }
2

Got it solved.

public function getProductCustomOptionsData($observer)
    {
        $event = $observer->getEvent();
        $order = $event->getOrder();
        foreach ($order->getAllVisibleItems() as $item){

            $optionArray = $item->getProductOptions();
            foreach($optionArray['options'] as $option) {
                $str = $option['label'] . ' : ' . $option['value'];
                 Mage::log($str, null, 'taxi.log', true);               
            }
        }
    }
  • if you think your answer best suits your question, please accept it so as others know it's the right solution :) – Julien Lachal Jul 10 '15 at 7:39
  • ah yh, forgot about that :) – Julien Lachal Jul 10 '15 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.