Magento – How to filter product collection by price after tax

collection-filteringproductproduct-attribute

I am trying to filter product collection by price range:

$this->getLoadedProductCollection()->clear()
     ->addAttributeToFilter('price', array( 'lt' => 500 ) )
     ->addAttributeToFilter('price', array( 'gt' => 100 ) )
     ->load();

this works fine however Magento uses price before tax to select the range and I would like to select by price after tax.

Is there a filter property, like 'price_after_tax' that contains this value?
If not can somehow the current tax be calculated from the input range values? I could then calculate net price range.

Any other advice would be highly appreciated. Thanks!

  • The only option for me is to deal with this issue programmatically, from module's level. I would rather not change Magento's configuration(product's are already uploaded, other custom modules installed).

Best Answer

The price attribute is much like any other - just a value assigned to that product, essentially what you are saying you want to do is filter by value other than what is entered (being price after tax) which you obviously can't do.

What you need to do here is instead alter what the product price represents from being the price without tax, to the price with tax. So under system->configuration->tax->calculation settings change catalog prices from excluding tax which is what it sounds like they are currently to including tax.

Obviously this means having to change the price all of your catalog items to be the price including tax, but if you want to be able to filter by price including tax this is your best, cleanest option.