magento - 在 magento 1.7.0.2 中将客户名称添加到订单网格中

标签 magento magento-1.7

我正在尝试在位于此处的销售订单网格中为客户名称添加一个新:

App/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

我想添加客户名称,例如“管理客户”中的“名称”。

我添加了以下代码:

protected function _getCollectionClass()
{
    return 'sales/order_grid_collection';
}

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    /*junpeng add start*/

    $collection->getSelect()
    ->join(
    'customer_entity',
    'main_table.customer_id = customer_entity.entity_id', array('email' => 'email'));

    $collection->getSelect()->join(
    'customer_entity_varchar',
    'main_table.entity_id = customer_entity_varchar.entity_id', array('name' => 'value')
    );

    /*junpeng add end*/
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
protected function _prepareColumns()
{
    $this->addColumn('name', array(
        'header'    => Mage::helper('sales')->__('Customer Name'),
        'index' => 'name',
    ));

    $this->addColumn('email', array(
        'header'    => Mage::helper('Sales')->__('Customer Email'),
        'index'     => 'email',
        'type'        => 'text',
    ));
}

客户电子邮件可以,但添加客户名称不起作用!

有人可以帮我解决这个问题吗?

最佳答案

您无法仅通过一行代码连接获取客户名称。名字和姓氏是不同的属性,您需要将它们与原始集合连接起来,然后连接它们以显示为全名。

所以基本上,替换

$collection->getSelect()->join(
    'customer_entity_varchar',
    'main_table.entity_id = customer_entity_varchar.entity_id', array('name' => 'value')
    );

使用此代码

$fn = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
$ln = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
$collection->getSelect()
    ->join(array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.customer_id', array('firstname' => 'value'))
    ->where('ce1.attribute_id='.$fn->getAttributeId()) 
    ->join(array('ce2' => 'customer_entity_varchar'), 'ce2.entity_id=main_table.customer_id', array('lastname' => 'value'))
    ->where('ce2.attribute_id='.$ln->getAttributeId()) 
    ->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS customer_name"));

并将您获取客户名称的 _prepareColumns 方法中的 addColumn('name', 代码替换为:

$this->addColumn('customer_name', array(
        'header'    => Mage::helper('sales')->__('Customer Name'),
        'index' => 'customer_name',
        'filter_name' => 'customer_name'
    ));

关于magento - 在 magento 1.7.0.2 中将客户名称添加到订单网格中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16258674/

相关文章:

php - 进行Magento更新的最佳实践?

magento - 显示客户税号/增值税号

Magento Rest API 在登录后重定向到客户帐户

Magento导入产品错误

Magento 源模型约定

ruby - 使用 Magento SOAP API v1 和 Savon Ruby Gem v2 创建类别时获取 'Error cannot find parameter'

image - Magento 未在某些商店的缓存中生成图像

apache - mod_rewrite 规则在 apache 重启后失败

magento - 我如何在 Magento 中获取估计的运输邮政编码?

magento - 在 Magento 中将子类别更改为根类别