在客户管理管理网格中显示多选项客户属性 [英] Display multi-option customer attribute within customer management admin grid

查看:57
本文介绍了在客户管理管理网格中显示多选项客户属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,对于客户属性",我有一个多选项选择,我已经将其添加到管理客户"网格中.

Okay so with Customer Attributes I have a multi-option selection that I have added to the Manage Customers Grid.

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

我确实将我的属性添加到了Grid.php顶部的集合中:

I do have my attribute added to the collection at the top of my Grid.php:

->addAttributeToSelect('prod_codes')

这是我的_filterProdOptionsCondition方法:

protected function _filterProdOptionsCondition($collection, $column) {
    if(!$value = $column->getFilter()->getValue()) {
        return;
    }
    $this->getCollection()->addFieldToFilter('prod_codes', array('finset' => $value));
    #print($collection->getSelectSql());
}

现在,如果我只选择了一个选项,那么此工作就很好了,一旦我对客户属性应用了多个选项,我将在管理网格中得到一个空白结果,但是仍可搜索.

Now this work fine and dandy if I only have ONE of the options selected, once I apply more than one option to the customers attribute I will get a blank results within the admin grid, however it IS still searchable.

仔细观察未注释print($collection->getSelectSql());的情况,发现以逗号分隔的列表返回了属性ID值.

A close look with the print($collection->getSelectSql()); uncommented I see that the attribute ID values are being returned in an comma delimited list.

现在,在背景已经摆好我的问题时,是否有一种方法或"Magento"方式可以在我不知道的管理网格中显示这些多选项?还是我只需要简单地分解逗号值并调用一个新的集合来构建显示值?任何帮助表示赞赏!

Now onto my question with that background laid out, is there a method or "Magento" way to display these multi-options within the admin grid I'm just unaware of? Or do I need to simply get the comma values exploded and call for a new collection to build out the display values? Any help appreciated!

推荐答案

似乎我不得不扩展Column渲染器以预期逗号值并简单地渲染它们,我很惊讶这不是内置的,因为存在创建该功能的功能multioptions属性,但没有网格显示选项.

Appears I had to extend the Column renderer to anticipate comma values and simply render them, I'm amazed this isn't built in since the functionality exists to create the multioptions attributes but no grid display option for it.

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

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

这篇关于在客户管理管理网格中显示多选项客户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆