Magento – How to add custom fields to custom shipping method(at onepage checkout)

checkoutformsmagento-1shipping-methods

I created previously custom payment methods.For that I added successfully extra fields using following code in my model logic.

protected $_formBlockType = 'newmodule/purchaseorder';
protected $_infoBlockType = 'newmodule/purchaseorderinfo';

But magento didn't provide any logic for creating forms in shipping module.
Please give me some direction to this?

Best Answer

It's not intended. If you look at the template app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml which shows the available shipping methods, no additional blocks are loaded and there is no kind of hook to change the HTML either. You would have to replace this template and implement something on your own.

Another possibility is to add custom fields to the shipping_method form that are not related to a specific shipping method, in the block checkout.onepage.shipping_method.additional. Unfortunately this one doesn't render its children by default, like I would expect from an "additional" block, but this requires only little change:

Copy app/design/frontend/base/default/template/checkout/onepage/shipping_method/additional.phtml, add echo $this->getChildHtml() at the end and replace it in your modules layout XML file.

Then you can add new blocks inside it with anything you want. You could also use JavaScript to display the form only if a specific shipping method is selected.