Question

I want to give access to 2 new roles. This new role will manage the customers, but one will manage the customers of the 'group X' and the other the 'group Y'. Is there a solution to filter this?

I mean, 'role 1' will not see customers group Y, but group X, and role 2 the opposite of role 1.

Is this possible? I searched for extensions but the research was useless.

Thanks.

Was it helpful?

Solution

You will have to create a custom module for such since Magento's ACL isn't that fine grained for control. Normally I would just override the customer grid admin block, but I've been making it a point to learn ways to do things with observers, so I learned a few things as well, hope this helps!

the modules config.xml

<config>
    <adminhtml>
        <events>
            <eav_collection_abstract_load_before>
                <observers>
                    <groupusersbyroles>
                        <class>namespace_adminusergroups_model_usergroups</class>
                        <method>gridByUsers</method>
                    </groupusersbyroles>
                </observers>
            </eav_collection_abstract_load_before>
        </events>
    </adminhtml>
</config>

the modules Model for the event observer configured above (your name space will vary in the <class> node of the config.xml:

public function gridByUsers($observer) {

    $collection = $observer->getCollection();
    if ($collection instanceof Mage_Customer_Model_Resource_Customer_Collection) {

        // Check for Admin's user group role ID
        $adminRoleId = Mage::getSingleton('admin/session')->getUser()->getRole()->getRoleId();            
        if ($adminRoleId == "1") {

            // filter out customers by their group ID
            $collection->addFieldToFilter('group_id', '1');

            // remove group column from grid layout
            $block = Mage::app()->getLayout()->getBlock('customer.grid');
            $block->removeColumn('group');
        }
    }

}

Keep in mind this is only with hardcoded values for the Admin's role ID and the Customers Group ID, you would most likely want to create an custom customer attribute to associate the two IDs together. If you are only doing it for a handful of Admin's Role and Customer Group's it may suffice with a simple array or just adding extra conditioning for your IDs.

Also here's a semi-related article:

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top