开发者

How to addAttributeToFilter?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜