This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Saturday 6 July 2013

Magento : Using Observer add the cart quote details to order item

Hi,

For Set the Cart Quote Items to the Order using the Observer. Using the "sales_convert_quote_item_to_order_item" Observer we can Add Custom Details of cart to the Order in magento.


1) Refer this Post = http://developerforums.blogspot.com/2013/07/using-observer-add-custom-price-for.html

Notice ::::>
                      Using this Post you can only set the Custom Details and Price to cart only, so for Save that Details to the Order you need to use another Event of Magento.  


2) Then Open your Module config.xml

    Copy-Paste below code Inside  <event> ...................   </event>  Tag.

    <sales_convert_quote_item_to_order_item> <!--Here Event Name as per your Requirement -->
                <observers>   
                    <{Namespace}_{Module Name}_Model_Observer>              
                        <type>singleton</type>
                        <class>{Namespace}_{Module Name}__Model_Observer</class>
                        <method>setdetailstocart</method>
                    </{Namespace}_{Module Name}__Model_Observer>                  
                </observers>      
   </sales_convert_quote_item_to_order_item>

3)  Open your   "Model/Observer.php"

   Use below Code

  class {Namespace}/{Module Name}_Model_Observer
  {
         $quoteItem = $observer->getItem();
            if ($additionalOptions = $quoteItem->getOptionByCode('additional_options'))
            {
                $orderItem = $observer->getOrderItem();
                $options = $orderItem->getProductOptions();
                $options['additional_options'] = unserialize($additionalOptions->getValue());
                $orderItem->setProductOptions($options);
            }
}

4) Clear all Cache and Index of your Site


Enjoy, This is work for me in Magento 1.7.0.2

    
, ,

No comments:

Post a Comment