Добавление столбца в сетку клиентов в Magento - Данные не заполняются


Попытка добавить столбец с пользовательским атрибутом в сетку клиентов администратора в Magento версии 1.1

У меня этот модуль настроен следующим образом:

Config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <WACI_AdminHtmlExt>
            <version>0.1.0</version>
        </WACI_AdminHtmlExt>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <customer_grid>WACI_AdminHtmlExt_Block_Customer_Grid</customer_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

WACI/AdminHtmlExt/Block/Customer/Grid.php

<?php
/**
 * Adminhtml customer grid block
 *
 * @category   WACI
 * @package    WACI_AdminhtmlExt
 * @author     
 */

class WACI_AdminHtmlExt_Block_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{

    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('customer/customer_collection')
            ->addNameToSelect()
            ->addAttributeToSelect('email')
            ->addAttributeToSelect('created_at')
            ->addAttributeToSelect('group_id')
            ->addAttributeToSelect('customer_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');

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }


    protected function _prepareColumns()
    {
        $this->addColumn('entity_id', array(
            'header'    => Mage::helper('customer')->__('ID'),
            'width'     => '50px',
            'index'     => 'entity_id',
            'type'      => 'number',
        ));

       $this->addColumn('customer_id', array(
            'header'    => Mage::helper('customer')->__('Dynamics ID'),
            'width'     => '75px',
            'index'     => 'customer_id',
        ));

        //... rest of the function, removing a couple columns...


        return parent::_prepareColumns();
    }
}

Customer_id, в данном случае это пользовательский атрибут (отслеживание внутреннего идентификатора клиента)... Не уверен, что мне нужно добавить логику для правильного отображения этого? Но его появление в администраторе просто отлично, иначе.

Я прочитал пару статей, в которых упоминается добавление средства визуализации для новых полей в сетках, подобных этой, - но так же многие вообще не упоминают об этом.

Не совсем уверен, куда идти отсюда -

Приветствия





Обновление

Просто чтобы уточнить для тех, кому нужно это решение:

class WACI_AdminHtmlExt_Block_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{

    /*protected function _prepareCollection()
        {
            $collection = Mage::getResourceModel('customer/customer_collection')
                ->addNameToSelect()
                ->addAttributeToSelect('email')
                ->addAttributeToSelect('created_at')
                ->addAttributeToSelect('group_id')
                ->addAttributeToSelect('customer_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');

            $this->setCollection($collection);

            return parent::_prepareCollection();
    }*/

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

    protected function _prepareColumns()
    {

        $this->addColumn('customer_id', array(
            'header'    => Mage::helper('customer')->__('Dynamics ID'),
            'width'     => '75px',
            'index'     => 'customer_id',
        ));

        $this->addColumnsOrder('customer_id','entity_id');

        parent::_prepareColumns();

        $this->removeColumn('billing_country_id');


        return $this;
    }
}

Это то, что я наконец-то нашел. Пропущен вызов _prepareCollenctions().

Приветствия

Author: Bosworth99, 2012-09-13

2 answers

Проблема заключается в том, что ваш оператор return вызывает parent::_prepareCollection() в сочетании с тем фактом, что вы расширяете исходный класс. Вызывая родительский класс после своего класса, вы заменяете созданный вами объект коллекции исходным. То, что вам на самом деле нужно вызвать, - это родительский класс, который вы перегружаете, что вы можете сделать так...

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('created_at')
        ->addAttributeToSelect('group_id')
        ->addAttributeToSelect('customer_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');

    $this->setCollection($collection);

    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}
 2
Author: Peter O'Callaghan, 2012-09-13 18:57:27

Извините, что неправильно прочитал блок кода из-за разрыва строки, когда я впервые ответил.

Похоже, что ваш метод createBlock() не возвращает допустимый объект.

 0
Author: Mike Brant, 2012-09-13 17:56:35