Grid Magento-SQLSTATE[42S22]:未找到列:1054未知列';账单名称';在';其中第'条;

Grid Magento-SQLSTATE[42S22]:未找到列:1054未知列';账单名称';在';其中第'条;,grid,magento-1.5,magento,Grid,Magento 1.5,Magento,我已经更改了app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php来定制订单网格中的内容 在\u getCollectionClass()中,我有: protected function _getCollectionClass() { //return 'sales/order_grid_collection'; return 'sales/order_collection'; } protected function

我已经更改了app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php来定制订单网格中的内容

\u getCollectionClass()
中,我有:

protected function _getCollectionClass()
{
    //return 'sales/order_grid_collection';
    return 'sales/order_collection';
}
protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $collection->getSelect()->joinLeft(array('s1' => 'sales_flat_order_address'),'main_table.shipping_address_id = s1.entity_id',array('region','firstname','lastname'));
    $collection->getSelect()->joinLeft(array('s2'=>'sales_flat_order_address'),'main_table.billing_address_id = s2.entity_id',array('firstname','lastname'));

    $collection->getSelect()->columns(new Zend_Db_Expr("CONCAT(s2.firstname, ' ',s2.lastname) AS billing_name"));
    $collection->getSelect()->columns(new Zend_Db_Expr("CONCAT(s1.firstname, ' ',s1.lastname) AS shipping_name"));

$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total')); // New 
    $collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street','sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone')); // New


    $this->setCollection($collection);

    return parent::_prepareCollection();
}
\u prepareCollection()
中,我有:

protected function _getCollectionClass()
{
    //return 'sales/order_grid_collection';
    return 'sales/order_collection';
}
protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $collection->getSelect()->joinLeft(array('s1' => 'sales_flat_order_address'),'main_table.shipping_address_id = s1.entity_id',array('region','firstname','lastname'));
    $collection->getSelect()->joinLeft(array('s2'=>'sales_flat_order_address'),'main_table.billing_address_id = s2.entity_id',array('firstname','lastname'));

    $collection->getSelect()->columns(new Zend_Db_Expr("CONCAT(s2.firstname, ' ',s2.lastname) AS billing_name"));
    $collection->getSelect()->columns(new Zend_Db_Expr("CONCAT(s1.firstname, ' ',s1.lastname) AS shipping_name"));

$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total')); // New 
    $collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street','sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone')); // New


    $this->setCollection($collection);

    return parent::_prepareCollection();
}
现在我已经更改了
\u prepareColumns()
,添加了我所需的字段,所有操作都很好!除了一件事

当我通过计费配送搜索订单时,我得到一个错误。我已经在所有必要的组件中添加了过滤器索引(
'filter\u index'=>'theindex'
),除了这两个字段计费发货,它们都工作得很好

所以我也在上面加了过滤索引

一切都很顺利。我可以搜索其他字段,但只要搜索账单配送字段,就会出现以下错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'billing_name' in 'where clause'
我试过各种方法,但似乎都不管用。有人能帮忙吗



当我后退一分钟,开始查看数据库时,我突然意识到我想要的字段已经格式化了。我不需要连接/合并任何内容。我只需要像调用其他字段一样调用这些字段

我的新
\u prepareCollection()
函数是:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $collection->getSelect()->joinLeft(array('sfog' => 'sales_flat_order_grid'),'main_table.entity_id = sfog.entity_id',array('sfog.shipping_name','sfog.billing_name'));

$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total')); // New 
    $collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street','sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone')); // New


    $this->setCollection($collection);

    return parent::_prepareCollection();
}
请注意
sfog
数组

这将进入数据库的
sales\u flat\u order\u网格
表,并像原始网格中一样获取预格式化的名称。我想知道这是否与从这个表中调用原始网格有关(讽刺)——:P

然后,就像确保在两个名称字段中执行
filter\u index
(与所有其他字段一样)

例如:

$this->addColumn('billing_name', array(
        'header' => Mage::helper('sales')->__('Bill to Name'),
        'index' => 'billing_name',
        'filter_index' => 'sfog.billing_name',
    ));
这就是她写的全部