我想要Mage_Adminhtml_Block_Dashboard_Orders_Grid setCollection重写。
我完成了:
public function setCollection($collection)
{
$connection = $collection->getConnection();
if(!Mage::helper("accountmanager")->isAdmin()){
$userId = Mage::helper("accountmanager")->getUserId();
$collection->getSelect()->joinInner(array('items_table'=>'sales_flat_order_item'),
'main_table.entity_id = items_table.order_id ',
null);
$collection->getSelect()->joinInner(array('e'=>'catalog_product_entity'),
'items_table.product_id = e.entity_id ',
null);
$collection->getSelect()->joinLeft(array('at_created_by'=>'catalog_product_entity_int'),
'(`at_created_by`.`entity_id` = `e`.`entity_id`) AND (`at_created_by`.`attribute_id` = 141) AND (`at_created_by`.`store_id` = 0) ',
null);
$collection->getSelect()->where("at_created_by.value = '".$userId."'");
}
exit($collection->getSelect());
parent::setCollection($collection);
}
结果如下:
SELECT `main_table`.*, `main_table`.`total_item_count` AS `items_count`, CONCAT_WS(' ', main_table.customer_firstname, main_table.customer_lastname) AS `customer`, `main_table`.`base_grand_total` AS `revenue` FROM `sales_flat_order` AS `main_table` INNER JOIN `sales_flat_order_item` AS `items_table` ON main_table.entity_id = items_table.order_id INNER JOIN `catalog_product_entity` AS `e` ON items_table.product_id = e.entity_id LEFT JOIN `catalog_product_entity_int` AS `at_created_by` ON (`at_created_by`.`entity_id` = `e`.`entity_id`) AND (`at_created_by`.`attribute_id` = 141) AND (`at_created_by`.`store_id` = 0) WHERE (store_id = '1') AND (at_created_by.value = '3')
此sql错误:错误代码:1052。冠军:'store_id'dans where where est ambigu
我认为store_id没有别名'main_table'。
我的查询如何添加别名??
请帮帮我。
想你。