Question

I had set up a "Store Owner" role in Magento. Users with that role will be able to add/edit/delete products only.

What I need is some one to tell me how can I limit these users to see only their products in the list when they go to Catalog -> Manage Products ?

I want to achieve this with code editing if possible.

Also note that all users are using the same store.

Thanks

Was it helpful?

Solution

This is not an "out of the box" feature in Magento Community Edition (or Enterprise), so you'll need to write some code to make this work.

In general terms you'll want to:

  1. Add a (hidden?) attribute to the product to store the User Id of the product "owner".
  2. Write an event observer for catalog_product_save_before which assigns the current user's User Id field to the new product owner attribute.
  3. Rewrite the _prepareCollection or _addColumnFilterToCollection methods of Mage_Adminhtml_Block_Catalog_Product_Grid to add the product_owner attribute to the collection and filter it to just the current user.

That will ensure that the only products that appear in the grid for a given user are the products they own. However, I would also implement an observer on the controller_action_predispatch_adminhtml_catalog_product_edit and controller_action_predispatch_adminhtml_catalog_product_save events to check the product owner value on products before they're edited/saved to make sure the user hasn't tried to edit a product that doesn't appear on the grid.

If you need any further assistance with adding attributes, setting up block rewrites, or creating event observers, I'm sure those questions have already been answered on SO, this question is a bit too broad to answer at that level of detail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top