Reputation: 357
I want to filter the product collection in product Grid,
My requirement is, I am creating module where the vendor gets access to category products.
He will be allowed to see only the product which of particular vendor code.
I have added new attribute to product,
and in Grid.php file written following code. But not working. Please help.
$vendor = Mage::getSingleton('admin/session')->getUser()->getData('username');
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id')
->addAttributeToSelect('vendor')
->addAttributeToFilter(array('attribute'=>'vendor','eq'=> $vendor));
Upvotes: 1
Views: 743
Reputation: 2947
Try this
$collection->addFieldToFilter('vendor',$vendor);
Read more here http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections
Upvotes: 1