简体   繁体   中英

Magento filter products in Grid page on collection load

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));

Try this

$collection->addFieldToFilter('vendor',$vendor);

Read more here http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM