Pergunta

Eu tinha substituir _prepareCollection() método de Mage_Adminhtml_Block_Customer_Grid e adicionado seguintes linhas

->addAttributeToSelect('cus_city')
->addAttributeToSelect('cus_country')
->addAttributeToSelect('cus_state')

para:

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

e adicionar esses 3 colunas no _prepareColumns() como segue

$this->addColumn('cus_city', array(
    'header'    => Mage::helper('customer')->__('City'),
    'width'     => '100',
    'index'     => 'cus_city'
));

$this->addColumn('cus_country', array(
    'header'    => Mage::helper('customer')->__('Country'),
    'width'     => '100',
    'index'     => 'cus_country'
));

$data_array=array(); 
$statearray = Mage::getModel('directory/region')->getResourceCollection() ->addCountryFilter('IN')->load()->toOptionArray();
foreach($statearray as $states){
    $data_array[$states['value']] = $states['label'];
}

$this->addColumn('cus_state', array(
    'header'    => Mage::helper('customer')->__('State'),
    'width'     => '100',
    'type'   => 'options',
    'index'     => 'cus_state',
    'options' => $data_array,
));

Problema é esse de 3 colunas não está preenchendo com os dados quando ele é o substituído módulo e se eu adicionar o mesmo código no núcleo de 3 colunas preencher com os valores

Foi útil?

Solução

No final, você chamar o método original com o return parent::_prepareCollection();

Ele irá preparar a coleção novamente com os parâmetros padrão e substituir o seu.

Chamada de o grande pai

return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();

em vez de

return parent::_prepareCollection();

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top