2012-01-27 3 views
2

변경했습니다. app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php주문을 사용자 정의하려면 그리드를 주문하십시오. _getCollectionClass()에서Magento - SQLSTATE [42S22] : 열을 찾을 수 없음 : 1054 알 수없는 'where 절에'billing_name '열

나는이 있습니다

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

잠시 후에 다시 db를 살펴 보았을 때, 원하는 필드가 이미 형성되었음을 알게되었습니다. 나는 어떤 것을 연결/병합 할 필요가 없다.

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 배열 : 난 그냥 단순히

나의 새로운 _prepareCollection() 기능입니다 ... 이미 호출되고 있던 다른 것과 같은 필드를 호출 할 필요가 있었다.

이것은 데이터베이스의 테이블에 들어가며 원래의 눈금에서와 같이 서식이 미리 지정된 이름을 가져옵니다. P 단지 같은 (당신이 두 개의 이름 필드에 filter_index을 확인처럼

다음 : -이 원래 그리드는이 테이블 (풍자)에서 호출되고 있다는 사실과 아무 상관이있는 경우 이 궁금해 다른 모든)

예 :

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

그리고 그게 전부는 모두 그녀는 썼다!

관련 문제