我正在关注Ivan的教程(Adding order attribute to the orders grid in Magento 1.4.1)以向sales_order_grid表(Shipping Description文本)添加一个额外的列,并且它正在工作,除了它不会将sales_flat_order中的旧数据带到sales_order_grid中的新列。< / p>
我的SQL安装脚本正确地添加了列,因为我使用与sales_flat_order中相同的字段名称我认为我不需要观察者,但是将所有现有出货说明数据导入到shipping_description字段的代码没有运行。
我做错了什么?
我的SQL安装脚本:
<?php
/**
* Setup scripts, add new column and fulfills
* its values to existing rows
*
*/
/* @var $this Mage_Sales_Model_Mysql4_Setup */
$this->startSetup();
// Add column to grid table
$this->getConnection()->addColumn(
$this->getTable('sales/order_grid'),
'shipping_description',
"varchar(255) not null default ''"
);
// Add key to table for this field,
// it will improve the speed of searching & sorting by the field
$this->getConnection()->addKey(
$this->getTable('sales/order_grid'),
'shipping_description',
'shipping_description'
);
// fill existing rows with data
$select = $this->getConnection()->select();
$select->join(
array('order'=>$this->getTable('sales/order')),
$this->getConnection()->quoteInto('order.entity_id = order_grid.entity_id',''),
array('shipping_description' => 'shipping_description')
);
$this->getConnection()->query(
$select->crossUpdateFromSelect(
array('order_grid' => $this->getTable('sales/order_grid'))
)
);
$this->endSetup();
我正在使用Magento 1.5.1社区版!
感谢您的帮助!
答案 0 :(得分:4)
这应该有效:
$select = $this->getConnection()->select();
$select->join(
array('order_shipping'=>$this->getTable('sales/order')),//alias=>table_name
$this->getConnection()->quoteInto(
'order_shipping.entity_id = order_grid.entity_id',
Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
),//join clause
array('shipping_description' => 'shipping_description')//fields to get
);
$this->getConnection()->query(
$select->crossUpdateFromSelect(
array('order_grid' => $this->getTable('sales/order_grid'))
)
);
如果您愿意,请查看我的extension :) HTH