我已经重写了app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
&app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
并创建了一个渲染器来在网格中显示客户的电子邮件列。
这是我的渲染器文件:
class Mage_Adminhtml_Block_Renderer_Customer extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$model = Mage::getModel('customer/customer')->load($row->getCustomerId());
return $model->getEmail();
}
}
& 这是我的 Grid 更改(我刚刚添加了一个列,我打算让它可以搜索)
$this->addColumn('billing_name', array(
'header' => Mage::helper('sales')->__('Bill to Name'),
'index' => 'billing_name',
));
// this is new col.
$this->addColumn('customer_email', array(
'header' => Mage::helper('sales')->__('Customer Email'),
'renderer' => 'adminhtml/renderer_customer',
));
我得到了我想要的。但是这个 col/ 由于这个原因,我认为这个 col 有很多前导和尾随空格。不可搜索。任何人都可以建议可以做些什么来删除这些空白
提前谢谢了
编辑 几天后,我发现这些空白在网格中很常见,它与可搜索选项无关。任何人都可以建议如何使用渲染器在已添加到网格的可搜索中创建自定义列???谢谢
2 EDIT
Guys 根据clockworkgeek,我自定义_prepareCollection()
了覆盖网格的方法,如下所示
protected function _prepareCollection()
{
// 'sales/order_collection' is changed from 'sales/order_grid_collection'
$collection = Mage::getResourceModel('sales/order_collection');
$collection->addAttributeToSelect('*')
->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
->joinAttribute('billing_fax', 'order_address/fax', 'billing_address_id', null, 'left')
->joinAttribute('billing_telephone', 'order_address/telephone', 'billing_address_id', null, '')
->addExpressionAttributeToSelect('billing_name',
'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
array('billing_firstname', 'billing_lastname'))
->addExpressionAttributeToSelect('shipping_name',
'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
array('shipping_firstname', 'shipping_lastname'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
我还调查了对于 Grid Magento 从sales_flat_order_grid表而不是从sales_flat_order获取数据,这就是它根据 clockworkgeek第一个解决方案报告未知列错误的原因
当前实现的问题是 Magento 报告错误 致命错误:调用未定义的方法 Mage_Sales_Model_Mysql4_Order_Collection::addExpressionAttributeToSelect()
因为 Mage_Sales_Model_Mysql4_Order_Collection 没有 addExpressionAttributeToSelect 方法,而是它有addExpressionFieldToSelect方法现在我需要帮助来为 addExpressionAttributeToSelect 方法编写正确的语法。仅更改方法名称对我没有帮助。我也参考了文档