I want to save custom information in order_item-table
. These information where created in cart. So I do it like described in this post.
I have installed the attribute:
$installer->addAttribute('quote_item', 'final_delivery_time', $settings);
$installer->addAttribute('order_item', 'final_delivery_time', $settings);
declare the fieldset 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 cart 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 my field final_delivery_time
with this value in the sales_flat_quote_item
table
After I place the order in onepage-review
, I should also have this field in the sales_flat_order_item table
, but there is nothing. In the column stands null
.
So I need the value of the field saved in the order.
I found the solution
it's an observer I add 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());
}
}
}
...
so everything is saved in the order
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With