1

I want to create customer group admin to view orders only.

Basically, I have created 3 customer group - A, B, C

Now I want that there should be user (basically new admin roles) like Ma can see all orders done by a customer of group A

likewise, Mb can view all order done by a customer of Group B.

How can I do it ...

Any way to do it via observer, which observer should I write please guide me.

0
+100

Create a custom module. Then use a various observer to filter the collection related to customer and orders. If this admin user has limited ACL access then you may not need to implement all of the event listed below.

Config.xml

<config>
    <modules>
        <Company_Module>
            <version>0.1.0</version>
        </Company_Module>
    </modules>
    <global>
        <blocks>
            <company_module>
                <class>Company_Module_Block</class>
            </company_module>
        </blocks>
    </global>
   <adminhtml>
     <events>
          <sales_order_grid_collection_load_before>
              <observers>
                <layout_before>
                    <class>module/observer</class>
                    <method>handleOrderCollectionBefore</method>
                </layout_before>
              </observers>
           </sales_order_grid_collection_load_before>
          <eav_collection_abstract_load_before>
              <observers>
                <layout_before>
                    <class>module/observer</class>
                    <method>handleCustomerCollectionBefore</method>
                </layout_before>
              </observers>
           </eav_collection_abstract_load_before>
          <sales_order_invoice_grid_collection_load_before>
              <observers>
                <layout_before>
                    <class>module/observer</class>
                    <method>handleOrderCollectionBefore</method>
                </layout_before>
              </observers>
           </sales_order_invoice_grid_collection_load_before>
           <core_collection_abstract_load_before>
              <observers>
                <layout_before>
                    <class>module/observer</class>
                    <method>handleCoreCollectionBefore</method>
                </layout_before>
              </observers>
           </core_collection_abstract_load_before>
          <sales_order_creditmemo_grid_collection_load_before>
              <observers>
                <layout_before>
                    <class>module/observer</class>
                    <method>handleOrderCollectionBefore</method>
                </layout_before>
              </observers>
           </sales_order_creditmemo_grid_collection_load_before>
     </events>
    </adminhtml>
</config>

In observer.php

Company_Module_Model_Observer{
   public function handleOrderCollectionBefore(){
       $collection = $observer->getEvent()->getOrderGridCollection();

       //logic for getting customer group
       //customerGroupIds
      $collection->addAttributeToFilter('customer_group_id', array('in' => $customerGroupIds));
   }

   //limit access to customer
   public function handleCustomerCollectionBefore(){
       $collection = $observer->getCollection();
       if (strpos(get_class($collection),'Customer_Collection')){   
            //logic for getting customer group
            //only show customer from group they have access to
       }        
   }

   //limit access to invoice
   public function handleCoreCollectionBefore(){
       $collection = $observer->getCollection();
       if ($collection instanceof Mage_Sales_Model_Mysql4_Order_Grid_Collection)
       { 
           //logic for getting customer group and filter order
       }      
   }

}
3

This is an overly broad question, but I will take a stab at a simple implementation.

Once you've created the roles and linked them (however you want) with the customer groups, you can filter order collections for the admin grid using the sales_order_grid_collection_load_before event, adding your group filtering logic (the sales_flat_order table stores the customer_group_id field).

You'll want to encapsulate that order-to-customer-group logic somehow, as you will also want to filter/restrict access to individual orders.

  • can u please tell what to write in observer.php for it, with static paramter like show order for user group A – user1799722 Feb 16 '15 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.