質問

AdminHTMLカスタマーグリッド内の顧客のカスタム属性を表示したい。 私は新しいモジュールを作成することによってこれを実行し、setCollection Mage_Adminhtml_Block_Customer_Gridメソッドを拡張しました

public function setCollection($collection)
    {
        $collection->addAttributeToSelect('x_customer_category');
        parent::setCollection($collection);
    }
.

および私は観察者を介して列をView に追加します。

/**
     * Adds column to admin customers grid
     *
     * @param Varien_Event_Observer $observer
     *
     * @return Mscg_TemplateOverwrite_Model_Customer_Observer
     */
    public function addCustomerGroupToGrid(Varien_Event_Observer $observer)
    {
        $block = $observer->getBlock();
        if (!isset($block)) {
            return $this;
        }

        if ($block->getType() == 'adminhtml/customer_grid') {
            /* @var $block Mage_Adminhtml_Block_Customer_Grid */
            $block->addColumnAfter('x_customer_category', array(
                'header' => 'x_customer_category',
                'type'   => 'text',
                'index'  => 'x_customer_category',
            ), 'email');
        }
    }
.

しかし、これはオプション単位の属性であるため、顧客の選択された値のIDを取得するだけですが、特定のAttributのエンティティ値ではなく、TextValueを必要とします。

どうすればいいですか?

Enter Enter Image説明

役に立ちましたか?

解決

textからoptionsに列の種類を変更し、この形式のoptionsに値を含むkey => value要素を追加する必要があります。
このようなもの:

$block->addColumnAfter('x_customer_category', array(
            'header' => 'x_customer_category',
            'type'   => 'options',
            'index'  => 'x_customer_category',
            'options' => array(
                    'id1' => 'label 1',
                    'id2' => 'label 2',
                ),
        ), 'email');
.

可能な値が動的である場合は、まずすべての値を持つ配列を構築する必要があります。すべての可能な値を取得し、options要素に取得する配列を割り当てる方法を知っておく必要があります。
属性が標準のSELECT属性の場合は、次のように構築できます。

$attribute = Mage::getModel('eav/config')->getAttribute('customer', 'x_customer_category');
$options = $attribute->getSource()->getAllOptions(false);
$values = array();
foreach ($options as $option){
    $values[$option['value']] = $option['label'];
}
.

次のように列を追加します。

 $block->addColumnAfter('x_customer_category', array(
            'header' => 'x_customer_category',
            'type'   => 'options',
            'index'  => 'x_customer_category',
            'options' => $values,
        ), 'email');
.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top