在管理客户的管理区域中。
我添加了一个新的自定义列,但它没有过滤,也不能按 asc / desc 排序
这是我的代码
protected function _prepareCollection()
{
$collection = Mage::getResourceModel(’customer/customer_collection’)
->addNameToSelect()
->addAttributeToSelect(’email’)
->addAttributeToSelect(’created_at’)
->addAttributeToSelect(’group_id’)
->joinAttribute(’billing_postcode’, ‘customer_address/postcode’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_city’, ‘customer_address/city’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_telephone’, ‘customer_address/telephone’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_region’, ‘customer_address/region’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_country_id’, ‘customer_address/country_id’, ‘default_billing’, null, ‘left’);
$collection->getSelect()->columns(array(’CustomerStatus’ => new Zend_Db_Expr ("(SELECT
CustomerStatusFROM users WHERE MagentoID =e.entity_id)")));
$this->setCollection($collection);
return parent::_prepareCollection();
}
我尝试了很多不同的方法并添加了 _addColumnFilterToCollection 但似乎无法让它工作......</p>
protected function _addColumnFilterToCollection($column)
{
if ($column->getId() == 'CustomerStatus' && $column->getFilter()->getValue()) {
$val = $column->getFilter()->getValue();
$this->getCollection()->addFieldToFilter('CustomerStatus', array('like' => $val));
// $this->getCollection()->getSelect()->where('CustomerStatus= ?', $val);
}
return $this;
}
然后这就是我在 _preparecolumns 函数中添加列的方式
$this->addColumn('CustomerStatus', array(
'header' => Mage::helper('customer')->__('C Status'),
'width' => '100px',
'index' => 'CustomerStatus',
'filter_index' => 'CustomerStatus'
));
有任何想法吗?