magento-hackathon / AdvancedAcl

43 stars 12 forks source link

filter customer grids #19

Closed luemic closed 7 years ago

himansuahm commented 7 years ago

Create new observe event in etc/config.xml file as below.


<eav_collection_abstract_load_before>
    <observers>
        <magentohackathon_advancedacl>
            <type>singleton</type>
            <class>magentohackathon_advancedacl/observer_customer</class>
            <method>filterCustomerGrid</method>
        </magentohackathon_advancedacl>
    </observers>
</eav_collection_abstract_load_before>

put above code in adminhtml events.than create new Customer.php file in Model/Observer/ as below code.


class MagentoHackathon_AdvancedAcl_Model_Observer_Customer
{
    public function filterCustomerGrid(Varien_Event_Observer $observer) {
        $collection = $observer->getCollection();
        if (!isset($collection)){return;}
        if ($collection instanceof Mage_Customer_Model_Resource_Customer_Collection) {
            $storeIds = $this->getStoreIds();
            if(!empty($storeIds)){$collection->addAttributeToFilter('store_id',$storeIds);}
        }
    }
    protected function getStoreIds()
    {
        return Mage::helper('magentohackathon_advancedacl/data')->getActiveRole()->getStoreIds();
    }
}