Magento 1.9 – Add Field to Billing Information Step in One Page Checkout

magento-1.9

I want to add a new field to the billing information step of the one page checkout, then process the customers input in a handler responding to the checkout_submit_all_after_handler event.

I'm able to add the HTML to display my new field in the billing information step. If I use an observer responding to the controller_action_predispatch_checkout_onepage_saveBilling event, then I can get the data the customer added to the new field by using:

Mage::app()->getFrontController()->getRequest()->getPost()

However I want to process the customers input in response to the checkout_submit_all_after_handler as Magento has done some house keeping by this point, such as creating the customer. If I use the above code to get the post data in response to checkout_submit_all_after_handler, it only contains payment information data (which is what you'd expect as that's the last step in the checkout process).

How do I get the custom data the user filled out in an earlier step (billing information), but right at the end of the checkout process.

Best Answer

In order to get information on last stage of checkout you have to store it somewhere. Session object might be a good option for you. During controller_action_predispatch_checkout_onepage_saveBilling event assign your custom observer where you will prepopulate from the request object custom data:

$customField = Mage::app()->getFrontController()->getRequest()->getParam('custom_field')l
Mage::getSingleton('checkout/session')->setCustomField($customField);

Make sure to clean session object when you will get custom field at the checkout_submit_all_after event.

Hope it helps.

Related Topic