2011-12-22 21 views
0

sales_order_grid_collection_load_beforeオブザーバーイベントの現時点では、コレクションを使用できる場所は$collection = $observer->getEvent()->getOrderGridCollection();で、私は疑問に思っていますこのコレクションをorder属性の商品でフィルタリングします。 私が意味するのは、注文グリッド・コレクションにその注文に関連するサブ製品があることです。少なくとも1つの製品が特定の基準に一致する場合のみ注文を表示する必要があります(私の場合、製品にadmin_id属性これは製品を追加した管理者に設定されています)。Magento observer(sales_order_grid_collection_load_before)、商品属性別にコレクションを収集

ありがとうございます!

答えて

0

私は、次の手順を実行して、非常に同じようなことをやった:

  1. は、販売注文グリッドブロックをオーバーライドします。あなたがあなた自身の拡張機能を設定する必要がありますこれを行うには(あなたはすでにこれをやっている可能性があるように見えますが、念のため、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> 
    
  2. 私は、コピー/ app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.phpを/ app/code/local/Company/Module/Block/Sales/Orderにある

  3. にコピーします。クラス名をclass Company_Module_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Gridに変更しました

  4. 次に、_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関数の2番目の部分でフィルタリングします。私の場合、customer_group_idとcustomer_emailをグリッドに表示していましたので、必要に応じてユーザーが手動でフィルタをかけることができました。

+1

sales_flat_orderテーブルのcustomer_group_idはありませんか?私の場合、製品はsales_flat_orderにはありません。なぜなら、それは私には難しいものです。注文がある場合、複数の商品が関連付けられており、すべてが異なる 'admin_id'属性を持っています。ログインした管理者の「admin_id」が1つ以上ある注文のみを表示する必要があります。 –

+0

あなたは絶対に正しいです、上記のコードを見て、sales_flat_orderテーブルに左の結合を行い、 '$ collection-> getSelect() - > join( 'sales_flat_order'、 'main_table.entity_id = sales_flat_order ( 'customer_group_id'、 'customer_group_id'、 'customer_email' => 'customer_email')、null、 'left')) '。あなたは同じことをすることができます – CCBlackburn

+0

素晴らしい、私はあなたが言ったようにクラスをオーバーライドしなければならなかったが、私はあなたが言ったような項目をフィルタリングすることができませんでした。とにかくありがとう。 –

0

order_grid_collectionから直接アクセスできるかどうかわかりませんが(私はそう思わない)、sales_flat_order_itemでこのコレクションに参加し、必要に応じてフィルタリングすることができます。
HTH

+0

idsのリストをsales_flat_order_itemに追加するにはどうしたらよいですか?また、キャッシュをクリアすると空にはなりませんか? –

関連する問題