【发布时间】:2016-10-22 17:47:54
【问题描述】:
我想在 Magento 销售订单网格中显示客户电子邮件。我必须在我的本地模块中重写Mage_Adminhtml_Block_Sales_Order_Grid 以添加客户电子邮件的新列。我得到了每个订单的电子邮件价值,但排序和过滤没有按预期工作。
我花了一天多的时间来整理这个问题,但没有运气。另外,我在 SO 中也提到了一些答案。
下面是我尝试过的代码referring this answer,
public function setCollection($collection)
{
$collection->getSelect()->joinLeft(
array('sfo'=>'sales_flat_order'),
'main_table.entity_id=' . 'sfo' . '.entity_id',
array('*')
);
$collection->getSelect()->joinLeft(
array('sfoa'=>'sales_flat_order_address'),
'main_table.entity_id=' . 'sfoa' . '.parent_id',
array('email')
);
$collection->getSelect()->group(array('main_table.entity_id'));
$collection->addFilterToMap('increment_id', 'main_table.increment_id');
parent::setCollection($collection);
}
protected function _prepareColumns()
{
$this->addColumnAfter('email', array(
'header' => Mage::helper('sales')->__('Customer Email'),
'width' => '80px',
'type' => 'text',
'index' => 'email',
'filter_index' => 'sfoa.email',
'filter_condition_callback' => 'filter_last_login',
'order_callback' => 'sort_last_login',
), 'erp_confirm_order');
return parent::_prepareColumns();
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
function filter_last_login($collection, $column)
{
if (!$column->getFilter()->getCondition()) {
return;
}
$condition = $collection->getConnection()
->prepareSqlCondition('sfoa.email', $column->getFilter()->getCondition());
$collection->getSelect()->where($condition);
}
function sort_last_login($collection, $column)
{
$collection->getSelect()->order($column->getIndex() . ' ' . strtoupper($column->getDir()));
}
protected function _setCollectionOrder($column)
{
if ($column->getOrderCallback()) {
call_user_func($column->getOrderCallback(), $this->getCollection(), $column);
return $this;
}
return parent::_setCollectionOrder($column);
}
编辑 1
当我对客户电子邮件列进行排序和过滤时没有任何效果,当我单击其余默认网格列时也出现错误。
Integrity constraint violation: 1052 Column 'increment_id' in order clause is ambiguous, query was: SELECT `main_table`.*, `sfo`.*, `sfoa`.`email` FROM `sales_flat_order_grid` AS `main_table`
LEFT JOIN `sales_flat_order` AS `sfo` ON main_table.entity_id=sfo.entity_id
LEFT JOIN `sales_flat_order_address` AS `sfoa` ON main_table.entity_id=sfoa.parent_id GROUP BY `main_table`.`entity_id` ORDER BY increment_id ASC LIMIT 20
任何帮助都非常感谢。 谢谢,
【问题讨论】:
-
您是否收到任何错误消息,或者它根本什么都不做?
-
@Ian 进行排序和过滤时没有任何反应。请检查编辑 1。谢谢。
标签: magento magento-1.7 magento-1.9