开发者

add custom field to onepage checkout in magento

I'm trying to add custom fields to magento checkout onepage. I followed an example that doesn't work in 1.4.1 because of the move to a flat order table(I think) http://inchoo.net/ecommerce/magento/adding-a-new-tab-under-one-page-checkout-full-working-module/

I can see my custom tab in checkout page with my custom fields but I can't save the fields to the database.

  • How do I add columns to the quote and order tables? should this go to Mymod/sql/mymod_setup/mysql4-install-0.1.0.php or somewhere else?

  • How do I save the field to the db? Do I need to save it to the quote first? Do I use observer or something else? Do I need to have element in my module's config.xml? http://www.magentocommerce.com/boards/viewthread/19344/

Than开发者_开发技巧ks


Disclaimer: I have not touched Magento for 6 months. Now this is said, if you look in the app/code/core/Mage/Sales/sql/sales_setup/ directory you will find examples of how to modify order tables. For instance here is the content of app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php (without header comments):

$installer = $this;
/* @var $installer Mage_Sales_Model_Mysql4_Setup */

$installer->addAttribute('quote', 'subtotal', array('type'=>'decimal'));
$installer->addAttribute('quote', 'base_subtotal', array('type'=>'decimal'));

$installer->addAttribute('quote', 'subtotal_with_discount', array('type'=>'decimal'));
$installer->addAttribute('quote', 'base_subtotal_with_discount', array('type'=>'decimal'));

$this is initialized from what is found in the app/code/core/Mage/Sales/etc/config.xml following the config/global/resources/sales_setup/setup/class look into this class and you'll see it inherits from Mage_Eav_Model_Entity_Setup, the default setup class, and overrides or add some methods (for flat table support for instance).

To answer your first point (first question), you can add columns by using the addAttribute() method of this class. And the answer to the second question is yes, but you have to specify in the config.xml file of your module that you want to use Mage_Sales_Model_Mysql4_Setup as setup class. This is done by adding the same xml element found in app/code/core/Mage/Sales/etc/config.xml previously (replace sales_setup with yourmod_setup). So you dump your database, you check it works by using get_class($this) in your mysql4-install-0.1.0.php file, and then you restore your db. And you continue writing in your setup file, inspiring yourself from what you see in the files in app/code/core/Mage/Sales/sql/sales_setup and it should be fine! Now for the second point... I don't know... I hope it'll work automatically! Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜