2011-08-16 5 views
1

注文アイテムテーブルを販売注文グリッドに結合して正しくフィルタリングすることができたことがある人はいらっしゃいますか?Magento Sales Orderグリッド結合テーブル

私はまだのように、参加を完了することができました

protected function _prepareCollection() 
{ 
    parent::_prepareCollection(); 

    $collection = Mage::getResourceModel($this->_getCollectionClass()) 
    ->join(
     'sales/order_item', 
     '`sales/order_item`.order_id=`main_table`.entity_id', 
     array(
      'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'), 
      'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'), 
      ) 
     ); 
     $collection->getSelect()->group('entity_id'); 

    $this->setCollection($collection); 

    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection(); 
} 

しかし、私は今、そうのような列フィルタを追加しようとしています:

protected function _addColumnFilterToCollection($column) 
{ 
    if($this->getCollection() && $column->getFilter()->getValue()) 
    { 
     if($column->getId() == 'skus') 
     { 
      $this->getCollection()->join(
       'sales/order_item', 
       '`sales/order_item`.order_id=`main_table`.entity_id', 
       array(
        'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR "|")'), 
       ) 
      )->getSelect() 
       ->group('`main_table`.entity_id') 
       ->having('find_in_set(?, `main_table`.skus)', $column->getFilter()->getValue()); 

      return $this; 
     } 
     if($column->getId() == 'names') 
     { 

      $this->getCollection()->join(
       'sales/order_item', 
       '`sales/order_item`.order_id=`main_table`.entity_id', 
       array(
        'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'), 
       ) 
      )->getSelect() 
       ->group('`main_table`.entity_id') 
       ->having('find_in_set(?, names)', $column->getFilter()->getValue()); 

      return $this; 
     } 
    } 
    return parent::_addColumnFilterToCollection($column); 
} 

私はフィルタリングしようとするたびに、私はこのエラーを受け取ります: "カラムが見つかりません:1054不明なカラム 'having clause ...の中のmain_table.names'。

これまで経験したことがありましたら教えてください。

答えて

1

私は同じ問題を抱えていましたが、問題をもっと詳しく見てみると、ページングクエリがエラーを引き起こしていることがわかりました。お使いのモデルでgetSelectCountSqlを()変更し、あなたのページが表示されますが、あなたがgetSelectCountSqlを(変更する必要があり、次の

$countSelect->reset(Zend_Db_Select::HAVING); 

を追加)ページと結果の正確な数を取得TOT。

+0

誰かがこの答えを詳しく説明できますか?前もって感謝します – Aboodred1

関連する問題