I am trying to add a custom field containing the deliverydate
to the checkout of Magento. However I have problems saving it. I have added the field to the shipping_method
page and set up an observer in the config.xml
:
<frontend>
<events>
<controller_action_predispatch_checkout_onepage_saveShippingMethod>
<observers>
<mymodule_deliverydate>
<type>model</type>
<class>mymodule_deliverydate/observer</class>
<method>saveDeliverydate</method>
</mymodule_deliverydate>
</observers>
</controller_action_predispatch_checkout_onepage_saveShippingMethod>
</events>
</frontend>
Also, the quote to order conversion is set up in the config.xml
:
<global>
....
<fieldsets>
<sales_convert_quote>
<deliverydate>
<to_order>*</to_order>
</deliverydate>
</sales_convert_quote>
</fieldsets>
</global>
I have added a field deliverydate
to the sales_flat_order
table ( and sales_flat_quote
but Im not too sure if that was necessary) and set up the observer function like this:
public function saveDeliverydate($observer)
{
$order = $observer->getEvent()->getOrder();
$deliverydate = Mage::app()->getRequest()->getPost('deliverydate');
if(!empty($deliverydate))
{
$order->setDeliverydate($deliverydate);
}
}
However when the order has been placed, the field is empty in the database. What am I missing?