2

Given the following code:

$mageProductCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*')
                        ->addPriceData()
                        ->addFieldToFilter('status', array('eq' => '1')
                    );

How would I select only those products where price is greater than X? I have tried several things, including the following:

$mageProductCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*')
                        ->addPriceData()
                        ->addFieldToFilter('price', array('gt' => '0.00')
                        ->addFieldToFilter('status', array('eq' => '1')
                    );

But I can't figure it out. Thanks for any help.

2 Answers 2

4

use addAttributeToFilter('price', array('gt' => 0)); instead of

addFieldToFilter('price', array('gt' => '0.00')

1
  • 2
    Note that this will not handle calculated prices from discounts.
    – benmarks
    Commented Jun 18, 2013 at 13:37
4

The use of addAttributeToFilter is required:

$mageProductCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*')
                        ->addPriceData()
                        ->addAttributeToFilter('price', array('gt' => '0.00')
                        ->addFieldToFilter('status', array('eq' => '1')
                    );
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.