简体   繁体   English

Magento:在管理客户网格中添加自定义列

[英]Magento: add custom column in the admin customers grid

I wrote my own Magento function which calculates the percentage relation of orders to retours. 我编写了自己的Magento函数,该函数计算定单与重定路线的百分比关系。 In this way you can categorize customers into those, who never give bought things back (green - good customers), who sometimes make retours (yellow) and those ones, who return most of bought things (red - bad customers). 通过这种方式,您可以将客户分类为那些从不退还所购商品的顾客(绿色-好顾客),有时会重游的顾客(黄色)和返回大部分所购商品的顾客(红色-坏顾客)。

For this, I added a new db table which saves required information. 为此,我添加了一个新的数据库表,该表保存了必需的信息。

Now, I would like to add a new column in Magento's admin Customers->Manage customers which shows the appropriate color. 现在,我想在Magento的admin客户->管理客户中添加新列,以显示适当的颜色。 I managed to add the header of the new column, but I have no clue how to show my custom calculations from my custom db table. 我设法添加了新列的标题,但是我不知道如何显示自定义数据库表中的自定义计算。 Magento makes everything so complicated. Magento使一切变得如此复杂。

I edited the "app/code/core/Mage/Adminhtml/Block/Customer/Grid.php" and added the following code into the "prepareColumns": 我编辑了“ app / code / core / Mage / Adminhtml / Block / Customer / Grid.php”,并将以下代码添加到“ prepareColumns”中:

$this->addColumn('abc', array(
      'header' => "ABC"
    ));

So, how do I fill it with any data? 那么,如何填充任何数据呢?

I appreciate any help. 感谢您的帮助。

The very simplest solution is to edit the prepareCollection function in the same class, and join your table to the results set. 最简单的解决方案是在同一类中编辑prepareCollection函数,然后将表连接到结果集。 Then you simply have to set the correct index in your addColumn definition and the column should be populated. 然后,您只需要在addColumn定义中设置正确的索引,就应该填充该列。

Ideally of course you shouldn't be editing the core files, a slightly better option would be to instead rewrite the class, or you could go the whole hog and do it with events . 理想情况下,当然,您不应该编辑核心文件,一个更好的选择是改写类,或者您可以耗费大量精力并使用events进行操作

So do you maybe know how do to this? 那么,您是否知道该怎么做? What do all the parameters exactly mean?: 所有参数的确切含义是什么:

->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')

Please give me any piece of advice. 请给我任何建议。 Let's say, I would just make a raw SQL query for each customer, make some calculations and put it out. 假设,我只是为每个客户进行原始SQL查询,进行一些计算并将其发布。 I only need the customer's id to do this. 我只需要客户的ID即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM