Magento: getting your own quote field for an order

I want to save user information in the order_item table. This information is created in a cart. So I do this as described in this post: Magento Recycle Bin Extension

I set the attribute

$installer->addAttribute('quote_item', 'final_delivery_time', $settings); $installer->addAttribute('order_item', 'final_delivery_time', $settings); 

declare a set of fields in config.xml

 <fieldset> <sales_convert_quote_item> <final_delivery_time> <to_order_item>final_delivery_time</to_order_item> </final_delivery_time> </sales_convert_quote_item> <sales_convert_order_item> <final_delivery_time> <to_quote_item>*</to_quote_item> <to_invoice_item>*</to_invoice_item> <to_shipment_item>*</to_shipment_item> <to_cm_item>*</to_cm_item> </final_delivery_time> </sales_convert_order_item> </fieldset> 

and some code in the basket, for example

 $oQuote = Mage::getSingleton('checkout/session')->getQuote(); foreach ( $oQuote->getAllItems() as $_item ) { $orderItemId = $_item->getId(); $_item->setFinalDeliveryTime('some Value'); $_item->save(); } 

so I got a quote and I have a final_delivery_time field with this value in the sales_flat_quote_item table

after I placed the order in one page overview, I should also have this field in the sales_flat_order_item table, but there is nothing. The column is null. So I need the value of the field stored in order

+6
source share
1 answer

I found a solution

this is an observer I am adding the following code

config.xml

 ... <events> <sales_convert_quote_item_to_order_item> <observers> <quoteitem_set_custom_data> <class>DeliveryTime/observer</class> <method>setCustomDataOnQuoteItem</method> </quoteitem_set_custom_data> </observers> </sales_convert_quote_item_to_order_item> </events> ... 

Observer.php

 ... public function setCustomDataOnQuoteItem(Varien_Event_Observer $observer) { $quote = Mage::getModel('checkout/cart')->getQuote(); $orderItem = $observer->getOrderItem(); foreach ( $quote->getAllVisibleItems() as $_item ) { if ($_item->getSku() == $orderItem->getSku()) { $orderItem->setFinalDeliveryTime($_item->getFinalDeliveryTime()); } } } ... 

therefore everything is kept in order

+5
source

Source: https://habr.com/ru/post/920393/


All Articles