I am trying to get Collection of all available products in Magento & Filter that collection
Here is my code:
开发者_Python百科$searcher = Mage::getModel('catalog/product')->getCollection();
$searcher->addAttributeToSelect('name');
echo count($searcher);
$searcher->addAttributeToFilter('name',array('like' => 'paper'));
$searcher->load();
echo count($searcher);
Now first time it gives count 745(FOR ALL PRODUCTS) but after filtering it still shows 745.
EDIT: This works for me:
$searcher = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name')
->addAttributeToFilter('name',array('eq' => 'paper'));
$searcher->load();
echo count($searcher);
精彩评论