I am using this code to filter products by min and max price

updated code

     $collection = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToFilter('status', 1)
            ->addAttributeToFilter(array(array('attribute'=>'visibility', 'eq'=>"4")));
            $collection->addAttributeToFilter('year', array('in' => $years));
        if(!empty($minprice) && !empty($maxprice)){

But if products have special price it works wrong. I need to use final price here. How can I do this?

Answer that I found while exploring magento native layered navigation

$select = $collection->getSelect();
$select->where('price_index.final_price >= ' . $minprice);
$select->where('price_index.final_price < ' . $maxprice);

2 Answers 2


Well the field for "final price" has code final_price in Magento Eav product table.

First you have to add final price to the collection as below:

$collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');

Then you can filter the collection by final_price as below:

  • I am getting an error Fatal error: Call to a member function getBackend() on boolean in /app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816. In this line there is this code: $attrInstance = $this->getAttribute($attribute); $attrBackendStatic = $attrInstance->getBackend()->isStatic();
    – Anna
    Dec 22, 2015 at 12:34
  • Have you upgraded Magento recently to version ce 1.9 ? Which subversion ? ?
    – Vicky Dev
    Dec 22, 2015 at 12:35
  • version is
    – Anna
    Dec 22, 2015 at 12:35
  • @Jeremy It seems one of your attributes you're passing in the collection for filtering is broken, can you update your question to include the whole collection query you are using ?
    – Vicky Dev
    Dec 22, 2015 at 12:40
  • code was updated
    – Anna
    Dec 22, 2015 at 12:55

The safest way to add price filters is using the existing methods that take advantage of the price index.


// join the price index

// add filters
$collection->addPriceDataFieldFilter('%s <= %s', ['final_price', $minPrice]);
$collection->addPriceDataFieldFilter('%s >= %s', ['final_price', $maxPrice]);

Alternatively, look at the layered navigation to see how price filters are implemented there.

  • Would this be possible to add "easily" here? github.com/OpenMage/magento-lts (I'd like to help - but can assume adding it to the grid + adding the frontend filters would already come a long way). thx Sean
    – snh_nl
    Jul 3, 2017 at 11:52
  • This works perfectly for frontend, but how can I use that price filter in backend
    – Haris
    Mar 9, 2018 at 19:33

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.