Alex Rivera | Logout

Magento - Get Custom Option Value details from Option Value ID

Asked 2012-04-03T12:40:39.237
15

I have some intriguing questions related to Custom Options of Product:-

  1. Is there any difference between Options & Custom Options? This is because I have found two different properties for each Product details, in almost all product-related modules:

    • options
    • custom_options

    However there is only one class for only the Product Option, which tends to take care of the Custom Options. I am seeking clarification on this point.

  2. I am trying to fetch the Custom Options of an Ordered Item, including the Custom Option Price and Price Type. The problem is that Magento only stores the Option Value for the corresponding Ordered Item, and not all its details (like Custom Option Price & Price Type).

    So I created an object of this class Mage_Catalog_Model_Product_Option_Value, considering only the drop_down Custom Option Type. I've provided my code below, but it is still in vain and not fetching the desired results. How can I rectify this code?

Code for point #2:

echo "<pre>";
// $collection contains the whole Order Collection
foreach ($collection as $order) {
    foreach ($order->getAllItems() as $item) {
        $customOptions = $item->getProductOptions();
        
        foreach ($customOptions['options'] as $_eachOption) {
            // Value ID is stored in this field "option_value"
            $objModel = Mage::getModel('catalog/product_option_value')->load($_eachOption['option_value']);

            // This should provide all the details of this particular Option Value as chosen by the Customer when ordering this Product, but unfortunately it doesn't
            print_r($objModel->getData());
            
            /**
             * This gives the output as, without any details on Price and Price Type:-
             * Array
             * {
        
Edit
Report

1 Answer

2
$session= Mage::getSingleton('checkout/session');
$getotal = Mage::helper('checkout')->getQuote()->getGrandTotal();
foreach($session->getQuote()->getAllItems() as $item)
{
$options = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getProductOptionsCollection();
    foreach ($options as $o) 
    { 
        $title = $o->getTitle();
        $values = $o->getValues();

        foreach($values as $v)
        {
        $mydata = $v->getPrice();                           
        }

    }
}

You can use this code in order to get price set for custom options for products in shopping cart.

answered 2013-06-03T12:16:24.980

Your Answer