【问题标题】:add custom field to onepage checkout in magento在magento中将自定义字段添加到单页结帐
【发布时间】:2010-08-21 13:01:01
【问题描述】:

我正在尝试将自定义字段添加到 magento 结帐单页。 我遵循了一个在 1.4.1 中不起作用的示例,因为移至平面订单表(我认为)http://inchoo.net/ecommerce/magento/adding-a-new-tab-under-one-page-checkout-full-working-module/

我可以在结帐页面中看到我的自定义选项卡和我的自定义字段,但我无法将这些字段保存到数据库中。

  • 如何在报价表和订单表中添加列? 这应该去 Mymod/sql/mymod_setup/mysql4-install-0.1.0.php 还是其他地方?

  • 如何将字段保存到数据库? 我需要先将其保存到报价单中吗? 我使用观察者还是其他东西? 我需要在模块的 config.xml 中有元素吗? http://www.magentocommerce.com/boards/viewthread/19344/

谢谢

【问题讨论】:

    标签: magento checkout


    【解决方案1】:

    免责声明:我已经 6 个月没有接触过 Magento。 现在就是说,如果您查看 app/code/core/Mage/Sales/sql/sales_setup/ 目录,您将找到如何修改订单表的示例。例如,这里是 app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php 的内容(没有标题 cmets):

    $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 是从 app/code/core/Mage/Sales/etc/config.xml 中的内容初始化的,在 config/global/resources/sales_setup/setup/class 之后查看这个类,你会看到它继承自默认设置类 Mage_Eav_Model_Entity_Setup,并覆盖或添加一些方法(例如,用于平面表支持)。

    要回答您的第一点(第一个问题),您可以使用此类的 addAttribute() 方法添加列。第二个问题的答案是肯定的,但是您必须在模块的 config.xml 文件中指定要使用 Mage_Sales_Model_Mysql4_Setup 作为安装类。这是通过添加之前在 app/code/core/Mage/Sales/etc/config.xml 中找到的相同 xml 元素来完成的(将 sales_setup 替换为 yourmod_setup)。因此,您转储数据库,通过在 mysql4-install-0.1.0.php 文件中使用 get_class($this) 检查它是否有效,然后恢复您的数据库。然后你继续在你的设置文件中编写,从你在 app/code/core/Mage/Sales/sql/sales_setup 文件中看到的内容中启发自己,它应该没问题! 现在是第二点......我不知道......我希望它会自动工作! 祝你好运!

    【讨论】:

    • 我认为它不适用于 1.4.1,因为该表已从 EAV 更改为 flat。查看mysql4-upgrade-1.4.0.2-1.4.0.3.php。他们使用 addColumn 而不是 addAttribute。
    • @pablo:你看我的回答了吗?如果说添加了一些用于平板支持的方法。 addAttribute() 方法就是这种情况。看看 Mage_Sales_Model_Mysql4_Setup 类。
    • 我错过了您建议使用销售设置模块的事实。我会尝试并报告我的结果。谢谢。
    • 在同一个模块中,我需要向销售资料添加属性并创建一个自定义平面表,因此我使用的是:$setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');用于销售和 $setup = new Mage_Eav_Model_Entity_Setup('core_setup');为个人资料。谢谢
    猜你喜欢
    • 2017-09-17
    • 2012-09-11
    • 2013-02-19
    • 1970-01-01
    • 2021-11-18
    • 2014-05-05
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多