Magento通过连接属性值开票网格过滤器

时间:2015-02-17 21:11:17

标签: magento

我正在使用以下代码在Magento发票网格中包含一个名为“sales rep”的自定义属性:

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”属性“filter”设置为“false”,这就完美了。

如何允许用户按此加入属性进行过滤?

1 个答案:

答案 0 :(得分:0)

您应该像这样添加您的专栏:

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