2015-02-17 42 views
0

我用下面的代碼包括自定義屬性,標題爲「銷售代表」 Magento的發票網格內的過濾器:Magento的發票電網通過加入屬性值

protected function _prepareCollection() { 

    $sales_rep = Mage::getResourceSingleton('customer/customer')->getAttribute('sales_rep'); 

    $collection = Mage::getResourceModel('sales/order_invoice_grid_collection'); 
    $collection->join('invoice', 'main_table.entity_id = invoice.entity_id',array('order_id as order_id')); 
    $collection->join('order', 'invoice.order_id = order.entity_id',array('customer_id as customer_id')); 

    $collection->getSelect()->joinLeft(
     array('customer_sales_rep_table' => Mage::getSingleton('core/resource')->getTableName($sales_rep->getBackend()->getTable())), 
     'customer_sales_rep_table.entity_id = order.customer_id 
     AND customer_sales_rep_table.attribute_id = '.(int) $sales_rep->getAttributeId() . ' 
     ', 
     array('sales_rep'=>'value') 
    );  

    $this->setCollection($collection); 

    return parent::_prepareCollection(); 

} 

...

$this->addColumn('sales_rep', array(
    'header' => Mage::helper('sales')->__('Sales Rep'), 
    'index' => 'sales_rep', 
    'filter' => false 
)); 

只要將「addColumn」屬性「過濾器」設置爲「false」,這就完美了。

我該如何去允許用戶通過這個加入的屬性進行過濾?

回答

0

您應該添加您的列是這樣的:

$this->addColumn('sales_rep', array(
    'header' => Mage::helper('sales')->__('Sales Rep'), 
    'index' => 'sales_rep', 
    'filter_index' => 'customer_sales_rep_table.value' 
));