Magento - 将列添加到客户网格

发布于 2024-11-08 12:49:40 字数 42 浏览 0 评论 0原文

如何向 magento 客户网格添加自定义列?

多谢。

how to add a custom column to magento customer grid ?

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

〗斷ホ乔殘χμё〖 2024-11-15 12:49:40

您应该覆盖类 Mage_Adminhtml_Block_Customer_Grid (app/code/core/Mage/Adminhtml/Block/Customer/Grid.php) 并应用以下更改:

1 - 添加新属性以在 _prepareCollection() 函数中显示

2 - 添加新属性要在 _prepareColumns() 函数中显示的列

You should override the class Mage_Adminhtml_Block_Customer_Grid (app/code/core/Mage/Adminhtml/Block/Customer/Grid.php) and apply the following changes:

1 - add the new attribute to show in the _prepareCollection() function

2 - add the new column to show in the _prepareColumns() function

百合的盛世恋 2024-11-15 12:49:40

信用:http://www. leonhostetler.com/blog/magento-add-attribute-columns-in-manage-products-grid-201205/

Magento 不向我们提供能够选择将哪些属性作为列包含在“管理产品”网格中,但进行必要的代码更改相当简单。

生成管理产品网格的代码位于 /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php。您需要做的第一件事是将 Grid.php 复制到本地目录结构中。换句话说,您将 Grid.php 复制到以下位置; /app/code/local/Mage/Adminhtml/Block/Catalog/Product/.如果没有这样的位置,则必须创建必要的目录。文件的最终位置必须是; /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

现在,打开 Grid.php(本地目录结构中的那个)并开始编辑。找到以下代码;

$this->addColumn('sku',
大批(
'标题'=>法师::helper('目录')->__('SKU'),
'宽度' => '80 像素',
'索引' => 'sku',
));

这是将 SKU 列添加到产品网格的代码。现在,假设您有一个名为供应商 ID (supplier_ID) 的自定义属性,并且您希望这些属性也显示在“管理产品”网格上。将以下代码放置在上述代码块之前或之后,只要它位于 _prepareColumns() 内即可。

$this->addColumn('supplier_id',
    大批(
        '标题'=> Mage::helper('目录')->__('供应商ID'),
        '宽度' => '150 像素',
        '索引' => '供应商_id',
    ));

然后将以下行添加到 _prepareCollection() 中,其中列出了其他属性,如下所示;

->addAttributeToSelect('supplier_id')

这应该是您需要做的全部。您可能需要重新编译、刷新缓存、注销并重新登录才能看到产品网格中的更改。

上面的示例用于为文本字段的商店所有者添加具有目录输入类型的属性。如果您的属性使用下拉列表怎么办?上面的代码必须修改。

假设您有一个名为“Supplier”(供应商)的属性,它在产品编辑器中显示一个可供选择的供应商下拉列表。为此,我们可以将以下代码添加到 _prepareColumns() 中:

$supplier_items =
Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()->join('attribute','attribute.attribute_id=main_table.attribute_id',
'属性代码'); foreach($supplier_items 为 $supplier_item):
if ($supplier_item->getAttributeCode() == '供应商')
$supplier_options[$supplier_item->getOptionId()] = $supplier_item->getValue();结束foreach; $this->addColumn('供应商',
大批(
'标题'=>法师::helper('目录')->__('供应商'),
'宽度' => '150 像素',
'类型' => '选项',
'索引' => '供应商',
'选项' => $supplier_options, ));

我们不要忘记将以下行添加到 _prepareCollection() 中,其中列出了其他属性,如下所示;

->addAttributeToSelect('供应商')

这应该可以为您完成。重新编译、刷新缓存、注销,然后根据需要重新登录。

Credit: http://www.leonhostetler.com/blog/magento-add-attribute-columns-in-manage-products-grid-201205/

Magento does not provide us with the ability to choose which attributes are included as columns in the Manage Products grid but it’s fairly simple to make the necessary code changes.

The code that generates the Manage Products grid is at /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php. The first thing you need to do is copy Grid.php into to the local directory structure. In other words, you copy Grid.php into the following location; /app/code/local/Mage/Adminhtml/Block/Catalog/Product/. If there is no such location, then you must create the necessary directories. The final location of the file must be; /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

Now, open Grid.php (the one in the local directory structure) and begin editing. Find the following code;

$this->addColumn('sku',
array(
'header'=> Mage::helper('catalog')->__('SKU'),
'width' => '80px',
'index' => 'sku',
));

That’s the code that adds the SKU column to the product grid. Now, let’s say you have a custom attribute called Supplier ID (supplier_ID) and you want these to appear on the Manage Products grid as well. Place the following code either before or after the above block of code, as long as it’s inside _prepareColumns().

$this->addColumn('supplier_id',
    array(
        'header'=> Mage::helper('catalog')->__('Supplier ID'),
        'width' => '150px',
        'index' => 'supplier_id',
    ));

Then add the following line to _prepareCollection() where the other attributes are listed like this;

->addAttributeToSelect('supplier_id')

That should be all you need to do. You might have to re-compile, refresh your caches, logout, and log back in to see the change in your product grid.

The above example is for adding an attribute with a Catalog Input Type for Store Owner of Text Field. What if your attribute uses a dropdown list? The code above will have to be modified.

Let’s say you have an attribute called Supplier (supplier) which in the product editor presents a dropdown list of suppliers to choose from. To do this, we can add the following code to _prepareColumns():

$supplier_items =
Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()->join('attribute','attribute.attribute_id=main_table.attribute_id',
'attribute_code'); foreach ($supplier_items as $supplier_item) :
if ($supplier_item->getAttributeCode() == 'supplier')
$supplier_options[$supplier_item->getOptionId()] = $supplier_item->getValue(); endforeach; $this->addColumn('supplier',
array(
'header'=> Mage::helper('catalog')->__('supplier'),
'width' => '150px',
'type' => 'options',
'index' => 'supplier',
'options' => $supplier_options, ));

And let’s not forget to add the following line to _prepareCollection() where the other attributes are listed like this;

->addAttributeToSelect('supplier')

That should do it for you. Re-compile, refresh your caches, and logout and then back in if you need to.

巨坚强 2024-11-15 12:49:40

我已发布此处用真实的例子。

如果您需要添加 customer 属性,您可能需要仔细处理 join 语句。

->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')

I have publish here with real example.

If you need to add custome attribute, you may need to take care of join statements carefully.

->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
凉栀 2024-11-15 12:49:40

使用您的自定义模块重写客户网格块。

app/code/[本地或社区]/YourCompany/YourModule/etc/config.xml

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

app/code/[本地或社区]/YourCompany/YourModule/Block/Customer/Grid.php

<?php

class YourCompany_YourModule_Block_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{
    public function setCollection($collection)
    {
        $collection->addAttributeToSelect('confirmation');                    
        parent::setCollection($collection);
    }

    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->addColumn('confirmation', array(
                'header'=> Mage::helper('sales')->__('Confirmed'),
                'index' => 'confirmation',
                'type'  => 'text',
                'width' => '100px',
        ));
        return parent::_prepareColumns();
    }
}

详细说明可以在这里找到:

http://tipsmagento.blogspot.com/2011/03/add-new-column-on-customers-grid.html

Rewrite customer grid block with your custom module.

app/code/[local or community]/YourCompany/YourModule/etc/config.xml

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

app/code/[local or community]/YourCompany/YourModule/Block/Customer/Grid.php

<?php

class YourCompany_YourModule_Block_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{
    public function setCollection($collection)
    {
        $collection->addAttributeToSelect('confirmation');                    
        parent::setCollection($collection);
    }

    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->addColumn('confirmation', array(
                'header'=> Mage::helper('sales')->__('Confirmed'),
                'index' => 'confirmation',
                'type'  => 'text',
                'width' => '100px',
        ));
        return parent::_prepareColumns();
    }
}

Detailed explanation can be found here:

http://tipsmagento.blogspot.com/2011/03/add-new-column-on-customers-grid.html

颜漓半夏 2024-11-15 12:49:40

请务必查看 TigerMin for Magento。它是一个工具,您可以使用它轻松地将列添加到产品网格,甚至可以立即内联编辑值。这里是现场演示:http://demo.emvee-solutions.com/tigermin/

Make sure to check out TigerMin for Magento. It's a tool with which you can easily add columns to productsgrid and even inline edit values instantly. Here`s a live demo: http://demo.emvee-solutions.com/tigermin/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文