Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 在客户管理管理网格中显示多选项客户属性_Magento - Fatal编程技术网

Magento 在客户管理管理网格中显示多选项客户属性

Magento 在客户管理管理网格中显示多选项客户属性,magento,Magento,好的,关于客户属性,我有一个多选项选择,我已经添加到管理客户网格中 $prodCode = Mage::getSingleton('eav/config')->getAttribute('customer','prod_codes'); $prodCodeOptions = $prodCode->getSource()->getAllOptions(false); $prodOptions = array(); foreach($prodCod

好的,关于客户属性,我有一个多选项选择,我已经添加到管理客户网格中

    $prodCode = Mage::getSingleton('eav/config')->getAttribute('customer','prod_codes');
    $prodCodeOptions = $prodCode->getSource()->getAllOptions(false);
    $prodOptions = array();

    foreach($prodCodeOptions as $k)
        $prodOptions[$k['value']] = $k['label'];

    $this->addColumn('prod_codes', array(
        'header'    =>  Mage::helper('customer')->__('Product Code'),
        'width'     =>  '100',
        'index'     =>  'prod_codes',
        'type'      =>  'options',
        'options'   =>  $prodOptions,
        'filter_condition_callback'
                    => array($this, '_filterProdOptionsCondition'),
    ));
我确实将我的属性添加到了位于my Grid.php顶部的集合中:

->addAttributeToSelect(“产品代码”)

这是我的
\u filterProdOptionCondition
方法:

protected function _filterProdOptionsCondition($collection, $column) {
    if(!$value = $column->getFilter()->getValue()) {
        return;
    }
    $this->getCollection()->addFieldToFilter('prod_codes', array('finset' => $value));
    #print($collection->getSelectSql());
}
现在,如果我只选择了一个选项,那么这项工作很好,一旦我对customers属性应用了多个选项,我将在管理网格中得到一个空白结果,但是仍然可以搜索

仔细查看
print($collection->getSelectSql())未注释我看到属性ID值以逗号分隔的列表返回


现在,在我的问题的背景下,是否有一种方法或“Magento”方式在管理网格中显示这些多选项,我只是不知道?或者我需要简单地分解逗号值并调用一个新集合来构建显示值吗?感谢您的帮助

似乎我必须扩展列渲染器以预测逗号值并简单地渲染它们,我很惊讶这不是内置的,因为该功能可以创建多重选项属性,但没有网格显示选项

app/code/local/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Options.php

public function render(Varien_Object $row)
{
    $options = $this->getColumn()->getOptions();
    $showMissingOptionValues = (bool)$this->getColumn()->getShowMissingOptionValues();
    if (!empty($options) && is_array($options)) {
        $value = $row->getData($this->getColumn()->getIndex());
        if (is_array($value)) {
            $res = array();
            foreach ($value as $item) {
                if (isset($options[$item])) {
                    $res[] = $options[$item];
                }
                elseif ($showMissingOptionValues) {
                    $res[] = $item;
                }
            }
            return implode(', ', $res);
        }
        elseif (isset($options[$value])) {
            return $options[$value];
        } elseif (is_string($value)) { // <--- MY CHANGES HERE
            $values = explode(',', $value);
            $returnOptions = "";
            foreach($values as $k=>$v) {
                $returnOptions .= $options[$v]. ", ";
            }
            return substr($returnOptions, 0, -2);
        }
        return '';
    }
}
公共函数渲染(Varien_对象$row)
{
$options=$this->getColumn()->getOptions();
$showMissingOptionValues=(bool)$this->getColumn()->getShowMissingOptionValues();
if(!empty($options)&&is_数组($options)){
$value=$row->getData($this->getColumn()->getIndex());
if(是_数组($value)){
$res=array();
foreach(价值为$item){
如果(isset($options[$item])){
$res[]=$options[$item];
}
elseif($showMissingOptionValues){
$res[]=$item;
}
}
返回内爆(',',$res);
}
elseif(isset($options[$value])){
返回$options[$value];
}elseif(is_字符串($value)){/$v){
$returnOptions.=$options[$v]。“,”;
}
returnsubstr($returnOptions,0,-2);
}
返回“”;
}
}

好的,看来我需要扩展管理员小部件网格的选项渲染器。有趣的是,最模糊的答案是最有用的。我唯一要添加的是,我在添加到$returnOptions字符串的行周围添加了一个if(isset($options[$v])。如果$v不在$options中,我就会出错。这样做似乎已经解决了问题。