Magento – Get Custom Option Price in order

custom-optionsprice

I have custom option in my product i want to show selected custom option with price in order.
i have used below code to get all custom option

foreach ($sales_model->getAllItems() as $item) {

     $opts = $item->getProductOptions();


}

when print option array it will give array without price.so how can i get option price.

[options] => Array
    (
        [0] => Array
            (
                [label] => Tour Date
                [value] => 10/04/2014
                [print_value] => 10/04/2014
                [option_id] => 3433
                [option_type] => date
                [option_value] => 2014-04-10 00:00:00
                [custom_view] => 
            )

        [1] => Array
            (
                [label] => Adult
                [value] => 4
                [print_value] => 4
                [option_id] => 3434
                [option_type] => drop_down
                [option_value] => 14224
                [custom_view] => 
            )

        [2] => Array
            (
                [label] => Adult - Cruise + Lunch
                [value] => Yes
                [print_value] => Yes
                [option_id] => 3435
                [option_type] => checkbox
                [option_value] => 14231
                [custom_view] => 
            )

any help would be much appreciate.

Best Answer

The problem is that sales item contains information about selected option but not about option price.

So to get the price you need first:

  • get product object,
  • after get custom option collection(which contains all product custom options with prices).
  • get product custom option from collection by option id and get its price.

Try this:

foreach ($sales_model->getAllItems() as $item) {
     $selectedOpts = $item->getProductOptions();
     $productOpsCollection = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getProductOptionsCollection();
     foreach ($selectedOpts as $selectedOpt) {
         $optPrice = $productOpsCollection->getItemById($selectedOpt['option_id'])->getPrice();
     }
}
Related Topic