2

When I try using the addAttributeToFilter to the final_price, the list it not returned. It gives an error instead. PHP Fatal error: Call to a member function getBackend() on a non-object in /mnt/webdrive/foo.foo-web.net/app/code/core/Mage/Eav/Model/Entity/Abstract.php

However, when I use it with the normal price, it will work without any problems! I've used both addAttributeToSelect('final_price') as well as $collection->addFinalPrice() but neither seem to fix the issue.

The array I'm using is as follows:

 2016-08-17T12:12:33+00:00 DEBUG (7): Array
 (
     [0] => Array
         (
             [attribute] => final_price
             [from] => 50000.00
             [to] => 150000.00
         )
 )

It's being returned in a column in the query though. Is there no way to filter the collection based on that?

2

It's being returned in a column in the query though. Is there no way to filter the collection based on that?

It's a column from the joined price index, but not an attribute. That means, you cannot use addAttributeToFilter because Magento will try to load an EAV attribute final_price which does not exist.

But you can add the condition to the query directly:

$collection->getSelect()->where('final_price BETWEEN ? AND ?', [50000, 150000]);
  • I've tried that. Unfortunately that makes it omit items that are completely out of stock since for them the index/final_price is NULL. – Pat Aug 18 '16 at 7:49
  • 1
    Hmm, in this case you could try to fall back to "price" and replace 'final_price' with IFNULL(final_price, price) – Fabian Schmengler Aug 18 '16 at 7:56
  • That's what I did. But it did feel a little dirty, especially since it will ignore promotions. Hopefully the client will not care about that. – Pat Aug 18 '16 at 8:13
2

Going off the top of my head here but I don't think final_price is an actual attribute but rather calculated on the fly with PHP. Check you database table eav_attribute for the existence of that attribute code.

  • It's being returned in a column in the query though. Is there no way to filter the collection based on that? – Pat Aug 18 '16 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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