Php Magento管理客户网格

Php Magento管理客户网格,php,magento,Php,Magento,在管理客户的管理区域 我添加了一个新的自定义列,但它不过滤,也不可排序asc/desc 这是我的密码 protected function _prepareCollection() { $collection = Mage::getResourceModel(’customer/customer_collection’) ->addNameToSelect() ->addAttributeToSelect(’email’) ->addAttributeToSelect(’cre

在管理客户的管理区域

我添加了一个新的自定义列,但它不过滤,也不可排序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,但似乎无法让它工作

    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'
    ));

有什么想法吗

您可以使用
frame\u callback
填充列,并使用
filter\u条件\u fallback
搜索列,而不是直接尝试使列返回
CustomerStatus

我没有针对您的具体情况对此进行测试,但在过去将数据拉入管理网格时,我成功地使用了相同的技术

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 CustomerStatus FROM users WHERE MagentoID = e.entity_id)")));

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

并按如下方式更改addColumn:

$this->addColumn('CustomerStatus', array(
     'header'    => Mage::helper('customer')->__('C Status'),
     'width'     => '100px',
     'index'     => 'entity_id',
     'frame_callback' => array($this, 'callback_customerstatus'), // This calls the "callback_customerstatus" function below
     'filter_condition_callback' => array($this, 'filter_customerstatus'), // This calls the "filter_customerstatus" function that will modify your $collection to make searching possible
));

添加由
frame\u回调调用的这个新函数

public function callback_customerstatus($value, $row, $column, $isExport) {
    $entity_id = $value; // $value is passed from the Grid
    $sql = "SELECT `CustomerStatus` FROM `users` WHERE MagentoID=".$entity_id;
    $resource = Mage::getSingleton('core/resource');
    $readConnection = $resource->getConnection('core_read');
    $customer_status = $readConnection->fetchOne($sql); // Return one row with the selected value from "$sql" 

    return $customer_status;
}

添加名为filter_customerstatus()的新函数:


注意对
filter\u condition\u callback
的新调用,它添加了执行搜索函数所需的
where
条件

你能发布你的
\u prepareColumns()
函数吗?当然可以,我会编辑我的帖子嘿,谢谢-我想我快到了,我已经改成你的方式了,但它仍然没有过滤,好像这不起作用:$this->getCollection()->getSelect()->where(“CustomerStatus like?”,“%$value%”;是的,没有调用filter\u customerstatus-即使我添加了'filter\u condition\u callback'=>array($this,'filter\u customerstatus'),//这调用了“filter\u customerstatus”在我的专栏中,建议调用函数
filter\u customerstatus
,它只是不改变集合?不,函数没有被调用。我认为它无论如何都不会起作用,因为使用$this->getCollection()->getSelect()->where('CustomerStatus=?',$val);当我以前在addColumnFilterToCollection中使用它时,它不会工作??
public function filter_customerstatus($collection, $column) {
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }

    $this->getCollection()->getSelect()->where(
        "CustomerStatus like ?"
        , "%$value%");

    return $this;
}