2011-12-22 4 views
0

지금 sales_order_grid_collection_load_before 옵저버 이벤트로 작업 중이며, 컬렉션을 사용할 수있는 곳은 $collection = $observer->getEvent()->getOrderGridCollection();입니다. 가능한 경우 궁금합니다. order 특성의 제품으로이 컬렉션을 필터링하십시오. 그 의미는 주문 그리드 컬렉션에 해당 주문과 관련된 하위 제품이 있다는 것입니다. 적어도 하나의 제품이 특정 기준과 일치하면 주문을 표시해야합니다 (제 경우에는 제품에 admin_id 속성을 부여했습니다. 이는 제품을 추가 한 관리자에게 설정 됨).Magento 옵저버 (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/local/Company/Module/Block/Sales/Order의 내 확장 폴더에 app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php를 입력하십시오.

  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 함수의 두 번째 부분에서 필터링. 필자의 경우 customer_group_id와 customer_email을 그리드에 표시하여 필요할 경우 사용자가 수동으로 필터링 할 수 있도록했습니다.

+1

sales_flat_order 테이블에 customer_group_id가 없습니까? 제 경우에는 제품이 sales_flat_order에 없기 때문에 제게 어려움을 겪고 있습니다. 주문이있는 경우 여러 제품이 연결되어 있으며 모두 'admin_id'속성이 다르므로 하나 이상의 제품이있는 주문 만 표시해야합니다. 'admin_id'는 로그인 한 관리자의 주문입니다. –

+0

당신은 위의 코드를 살펴보면 sales_flat_order 테이블에 왼쪽 조인을 수행하여 $ 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,'왼쪽 '); 당신은 똑같은 일을 할 수 있습니다. – CCBlackburn

+0

위대한, 당신이 말한 것처럼 클래스를 오버라이드해야했지만, 말했듯이 아이템을 필터링 할 수 없었고, 루프를 끝내야 만했습니다. 어쨌든 고마워. –

0

order_grid_collection에서 제품에 직접 액세스 할 수 있는지 확실하지 않지만이 컬렉션을 sales_flat_order_item과 결합하여 원하는대로 필터링 할 수 있습니다.
HTH

+0

ID 목록을 sales_flat_order_item에 어떻게 추가 할 수 있으며 캐시를 지울 때 해당 항목이 비워지지 않습니까? –

관련 문제