我已經通過執行以下操作做了非常類似的事:
覆蓋的銷售訂單網格塊。要做到這一點,你需要建立自己的擴展名(它看起來像你可能已經這樣做,但爲了以防萬一,有在Magento wiki一些方便DOCO)
<config>
<modules>
<Company_Module>
<version>0.1.0</version>
</Company_Module>
</modules>
<global>
<blocks>
<company_module>
<class>Company_Module_Block</class>
</company_module>
<adminhtml>
<rewrite>
<sales_order_grid>Company_Module_Block_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
然後我複製了/ app/code/local/Company/Module/Block/Sales/Order
在我的擴展文件夾中的複製文件I將類名改爲class Company_Module_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
然後我改變了_prepareCollection函數。在這種情況下,我很感興趣,抓住從sales_flat_order表customer_group_id和CUSTOMER_EMAIL
protected function _prepareCollection() {
$collection = Mage::getResourceModel($this->_getCollectionClass());
// left join onto the sales_flat_order table, retrieving the customer_group_id and customer_email columns -< this can be expanded
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id=sales_flat_order.entity_id', array('customer_group_id'=>'customer_group_id', 'customer_email'=>'customer_email'), null, 'left');
// grab the current user and get their associated customer groups (additional coding required to associate the customer groups to an admin user
$user = Mage::getSingleton('admin/session')->getUser();
$roleId = implode('', $user->getRoles());
$customerGroupIds = Mage::getModel('admin/roles')->load($roleId)->getCustomerGroupIds();
$orders = Mage::getResourceModel('sales/order_collection');
// if the admin user has associated customer group ids then find the orders associated with those
// this would be where you would do your filtering of the products
if (count($customerGroupIds)) {
$orders->addAttributeToFilter('customer_group_id', array('in' => $customerGroupIds));
}
$orderIds = $orders->getAllIds();
$collection->addAttributeToFilter('entity_id', array('in' => $orderIds));
$this->setCollection($collection);
return parent::_prepareCollection();
}
您可能不需要加入到sales_flat_order表...你也許可以做到這一點只是做在上面顯示的_prepareCollection函數的第二部分進行過濾。就我而言,我在網格中顯示了customer_group_id和customer_email,以便用戶可以根據需要手動過濾。
雖然在sales_flat_order表中不是customer_group_id嗎?就我而言,這些產品不在sales_flat_order中,這就是它讓我感到困難的原因。如果我有訂單,有多個產品關聯,都有不同的'admin_id'屬性,我只需要顯示至少有一個產品的訂單,其中'admin_id'是已登錄管理員的產品。 – 2011-12-31 15:43:58
你是絕對正確的,如果你看看上面的代碼,我做一個左連接到sales_flat_order表來檢索它'$ collection-> getSelect() - > join('sales_flat_order','main_table.entity_id = sales_flat_order .entity_id',數組('customer_group_id'=>'customer_group_id','customer_email'=>'customer_email'),null,'left');'。你可以做同樣的事情 – CCBlackburn 2012-01-01 20:02:56
太好了,我不得不像你說的那樣重寫類,但是我不能像你說的那樣過濾這些項目,最後不得不循環遍歷它們,如果它們不在那裏,就刪除它們。不管怎麼說,還是要謝謝你。 – 2012-01-03 11:57:03