[英]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. 并在Grid.php文件中编写以下代码。 But not working.
但是没有用。 Please help.
请帮忙。
$vendor = Mage::getSingleton('admin/session')->getUser()->getData('username'); $ vendor =法师:: 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 在此处阅读更多信息http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.