开发者

How to addAttributeToFilter?

开发者 https://www.devze.com 2023-04-08 14:43 出处:网络
I am trying to get Collection of all available products in Magento & Filter that collection Here is my code:

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

精彩评论

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