添加到客户格在Magento列 - 数据不填充(Adding column to customer

2019-07-31 13:40发布

试图与在Magento V1.11自定义属性到管理客户网格中添加一列

我有这个模块设置,如下所示:

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 /座/客户/ 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,在这种情况下是一个自定义属性(跟踪内部客户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()调用。

干杯

Answer 1:

问题是你的回报声明,呼吁家长:: _ 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();
}


Answer 2:

对不起误0read代码块,因为断行的,当我第一次回答。

看来你的createBlock()方法没有返回一个有效的对象。



文章来源: Adding column to customer grid in Magento - Data not populating