2012-01-27 102 views
2

我已更改app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php以定製訂單網格上的內容。Magento - SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'billing_name'

_getCollectionClass()我有這樣的:

protected function _getCollectionClass() 
{ 
    //return 'sales/order_grid_collection'; 
    return 'sales/order_collection'; 
} 

_prepareCollection()我有這樣的:

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(); 
} 

現在我已經改變了_prepareColumns()加我必要的字段和所有的偉大工程!除了一件事......

當我通過結算搜索訂單航運,我得到一個錯誤。我已經添加filter_index的('filter_index' => 'theindex')到所有必要的組件,它們都除兩個領域結算航運工作的偉大。

所以我把filter_index也是這樣。

一切都很好。我可以搜索其他的領域,但只要我搜索了結算航運領域,我得到這個錯誤:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'billing_name' in 'where clause' 

我已經嘗試了各種各樣的事情,但似乎沒有任何工作。有人可以幫助!???


回答

6

當我退後一分鐘,剛開始看數據庫時,我發現我想要的字段已經被格式化了。我不需要連接/合併任何東西。我只是單純地需要調用像其他的領域已經被稱爲...

我的新_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_flat_order_grid表中,並抓取原始格網中的預格式化名稱。 我不知道這有什麼關係的事實,原來的電網正從該表(嘲諷)呼籲 - :P

然後,像剛纔你一定要做兩個名稱字段filter_index(如所有其他)

例子:

$this->addColumn('billing_name', array(
     'header' => Mage::helper('sales')->__('Bill to Name'), 
     'index' => 'billing_name', 
     'filter_index' => 'sfog.billing_name', 
    )); 

和多數民衆所有她寫!

相關問題