0

I have created observer for sales_quote_add_item event, i am using udropship_vendor module for vendor management. So price of a product is attached to product in custom options. I couldn't able to fetch udmp_vendor_data custom option please suggest.

$item = $observer->getQuoteItem();
echo '<pre>';  print_r( $item);  exit;

Is giving (part of an output)

[udmp_vendor_data] => Mage_Sales_Model_Quote_Item_Option Object
(
[_item:protected] => Mage_Sales_Model_Quote_Item Object
     *RECURSION*[_product:protected] => Azri_Unsetdeleverydate_Model_Catalog_Product Object
     *RECURSION*[_eventPrefix:protected] => core_abstract [_eventObject:protected] => object[_resourceName:protected] =>sales/quote_item_option                
     [_resource:protected] => [_resourceCollectionName:protected] => sales/quote_item_option_collection          
     [_cacheTag:protected] => [_dataSaveAllowed:protected] => 1
                              [_isObjectNew:protected] => 
                              [_data:protected] => Array
                                (
                                    [option_id] => 195991
                                    [item_id] => 25349
                                    [product_id] => 5566
                                    [code] => udmp_vendor_data
                                    [value] => a:25:{s:17:"vendor_product_id";s:6:"245116";s:9:"vendor_id";s:4:"3748";s:10:"product_id";s:4:"5566";s:8:"priority";s:4:"9999";s:12:"carrier_code";N;s:10:"vendor_sku";s:11:"87859_200-2";s:11:"vendor_cost";N;s:9:"stock_qty";N;s:10:"backorders";s:1:"0";s:14:"shipping_price";N;s:6:"status";s:1:"1";s:12:"reserved_qty";N;s:11:"avail_state";N;s:10:"avail_date";N;s:12:"vendor_title";N;s:12:"vendor_price";s:7:"27.0000";s:5:"state";s:3:"new";s:13:"special_price";N;s:17:"special_from_date";N;s:15:"special_to_date";N;s:11:"state_descr";N;s:12:"freeshipping";s:1:"0";s:16:"udropship_vendor";s:4:"3748";s:5:"label";s:9:"Lieferant";s:5:"value";s:15:"Propagroup GmbH";}
                                )
                               [_hasDataChanges:protected] => 1
                               [_origData:protected] => Array
                                  (
                                     [option_id] => 195991
                                     [item_id] => 25349
                                     [product_id] => 5566
                                     [code] => udmp_vendor_data
                                     [value] => a:25:{s:17:"vendor_product_id";s:6:"245116";s:9:"vendor_id";s:4:"3748";s:10:"product_id";s:4:"5566";s:8:"priority";s:4:"9999";s:12:"carrier_code";N;s:10:"vendor_sku";s:11:"87859_200-2";s:11:"vendor_cost";N;s:9:"stock_qty";N;s:10:"backorders";s:1:"0";s:14:"shipping_price";N;s:6:"status";s:1:"1";s:12:"reserved_qty";N;s:11:"avail_state";N;s:10:"avail_date";N;s:12:"vendor_title";N;s:12:"vendor_price";s:7:"27.0000";s:5:"state";s:3:"new";s:13:"special_price";N;s:17:"special_from_date";N;s:15:"special_to_date";N;s:11:"state_descr";N;s:12:"freeshipping";s:1:"0";s:16:"udropship_vendor";s:4:"3748";s:5:"label";s:9:"Lieferant";s:5:"value";s:15:"Propagroup GmbH";}
                                   )
                                [_idFieldName:protected] => option_id
                                [_isDeleted:protected] => 
                                [_oldFieldsMap:protected] => Array()
                                [_syncFieldsMap:protected] => Array()
                                )
                                )

I have tried $item->getOption() and $item->getOptionbycode('udmp_vendor_data') in by using both or not working. Please suggest.

0

Try this

    $product = $item->getProduct();
    $options = array();
    $optionIds = $item->getOptionByCode('option_ids');
    if ($optionIds) {
        $options = array();
        foreach (explode(',', $optionIds->getValue()) as $optionId) {
            $option = $product->getOptionById($optionId);
            if ($option) {
                $itemOption = $item->getOptionByCode('option_' . $option->getId());
                $group = $option->groupFactory($option->getType())
                    ->setOption($option)
                    ->setConfigurationItem($item)
                    ->setConfigurationItemOption($itemOption);

                if ('file' == $option->getType()) {
                    $downloadParams = $item->getFileDownloadParams();
                    if ($downloadParams) {
                        $url = $downloadParams->getUrl();
                        if ($url) {
                            $group->setCustomOptionDownloadUrl($url);
                        }
                        $urlParams = $downloadParams->getUrlParams();
                        if ($urlParams) {
                            $group->setCustomOptionUrlParams($urlParams);
                        }
                    }
                }

                $options[] = array(
                    'label' => $option->getTitle(),
                    'value' => $group->getFormattedOptionValue($itemOption->getValue()),
                    'print_value' => $group->getPrintableOptionValue($itemOption->getValue()),
                    'option_id' => $option->getId(),
                    'option_type' => $option->getType(),
                    'custom_view' => $group->isCustomizedView()
                );
            }
        }

        print_r($options);
    }
0

$product = $item->getProduct(); $data = Mage::helper('udropship/item')->getItemOption( $product, 'udmp_vendor_data'); $vendor_data = unserialize($data);

This has worked for me.

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.