How to add an input field in a delivery module in Zencart?

I was working on implementing the Royal Mail Airmail and DPD International delivery modules for a client. His website had been developed in Zencart and he wanted to use Royal Mail and DPD on his website. As there was no ready to use module available for these two so I got down to developing my own module.

After studying the formula provided by the client I decided it was best to hack the Zones delivery module (provided in Zencart 1.3.8 by default) and use it for the task in hand. After completing the module and testing it I deployed the code online. However, as luck would have it, client wanted to customize it further by allowing him to change the rate of VAT. Currently the rate of VAT is 15% in the UK but this would be increased to 17.5% in the year 2011 so he wanted to change the rate as and when he wanted.

So, I did the following changes in the includes/modules/shipping/<module_file>
where module_file is the name of the file I have created for my function. Your file can have any other name.

I added the following line in the function install()

$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('VAT', 'MODULE_DPDINTERNATIONAL_VAT', '', 'Enter rate of VAT:', '6', '1', 'zen_cfg_textarea(', now())");

To let the system know that VAT is an input field I had to add the key MODULE_DPDINTERNATIONAL_VAT in the keys array in the function keys().
I added it at the end.

To let Zencart know of this change I removed the module and reinstalled it and the input box for the VAT came up. I added the 15% in the input box and saved it. The system performed the calculations perfectly and

Hope the above helped.

Leave a Comment