我正在尝试将自定义字段添加到 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/

谢谢

有帮助吗?

解决方案

免责声明:我已经 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 的内容(没有标题注释):

$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 是根据 config/global/resources/sales_setup/setup/class 中的 app/code/core/Mage/Sales/etc/config.xml 中找到的内容进行初始化的,查看该类,您将看到它继承自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 中的文件中看到的内容中汲取灵感,应该没问题!现在来说第二点……我不知道...我希望它能自动工作!祝你好运!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top