How to add product specific attribute column to sales_flat_order_item table?

删除回忆录丶 提交于 2019-11-29 16:58:04

First of all, you need to add the new column to sales_flat_quote item, and sales_flat_order_item. the best explanation is here: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-6-magento-setup-resources

Your setup resource have to looks something like this:

$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')

In order to pass the data from the quote_item to order_item you need in to specify in your config.xml something like this: *

And then, in order to save the data in quote item, you need an observer, I suggest you to read this: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method The event you are looking for is In the observer method you'll have to do something like this

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

Greetings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!