如何将产品特定属性列添加到sales_flat_order_item表?

时间:2013-07-30 12:34:54

标签: php magento magento-1.7

在管理员面板中,我创建了一个product attribute作为“merchant”。我想在merchant表格中为sales_flat_order_item添加新列。应使用属性名称填充新列。如何在不使用事件观察器方法的情况下执行此操作? 任何帮助将不胜感激。 (我正在使用magento CE 1.7)

1 个答案:

答案 0 :(得分:3)

首先,您需要将新列添加到sales_flat_quote项目和sales_flat_order_item。 最好的解释是: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-6-magento-setup-resources

您的设置资源必须如下所示:

$installer = $this;
$installer->startSetup();
$installer->getConnection()
        ->addColumn(
            $installer->getTable('sales/quote_item'), 'merchant', 'VARCHAR(20) NOT NULL');
$installer->getConnection()
          ->addColumn(
            $installer->getTable('sales/order_item'), 'merchant', 'VARCHAR(20) NOT NULL')

为了将quote_item中的数据传递给order_item,您需要在config.xml中指定如下内容:                                                             *                                           

然后,为了将数据保存在引用项中,您需要一个观察者,我建议您阅读: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method 你正在寻找的事件是 在观察者方法中,你将不得不做这样的事情

class MyNamespace_Mymodule_Model_Observer
{
    public function saveTheMerchant($observer)
    {
        $item = $observer->getEvent()->getQuoteItem();
        $product = $item->getProduct();
        $item->setMerchant($product->getMethant());
        $item->save();
    }
}

问候。

相关问题