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.

3
  • you mean ordered item option values? Commented Jul 10, 2015 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
    Commented Jul 10, 2015 at 6:01
  • check my answer Commented Jul 10, 2015 at 6:22

2 Answers 2

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);               
            }
        }
    }
2
  • if you think your answer best suits your question, please accept it so as others know it's the right solution :) Commented Jul 10, 2015 at 7:39
  • ah yh, forgot about that :) Commented Jul 10, 2015 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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