# How to filter product collection by price after tax?

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). ## 3 Answers 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. • Thanks for your answer Jonathan. That's a good advice but unfortunately not an option for me. I can't change shop settings. The only way for me is to deal with this programmatically, from module's level. – Alan Nov 18 '14 at 12:45 • Well you don't unfortunately really have any other good options available to you, the next best way to do this would be to pass values to addAttributeToFilter() that represent price before tax as the price you enter on the product is the only one stored to the product, the rest are calculated on the fly. A third....highly unworkable solution imo is to add another attribute to each product with the price after tax and filter by that, but then you have to maintain 2 prices for each product - not great. – Jonathan Hussey Nov 18 '14 at 13:10 check out this admin setting may help you. System > Configuration > Sales > Tax > Price Display Settings The Tax - Price Display Settings determine whether the catalog prices and shipping prices that are displayed in your store include tax. • This option is set to 'Including and Excluding Tax' and that's how products' prices are showing in the front end. Unfortunately I can't set it to 'Including Tax' only. – Alan Nov 18 '14 at 12:25 I've found the answer: $calc = Mage::getSingleton('tax/calculation');
$rates =$calc->getRatesForAllProductTaxClasses($calc->getRateRequest()); foreach ($rates as $class=>$rate) {
$result =$rate;
}


and then I use \$result to calculate net price from visitor's input and use it in the filter. It seems to work pretty fine :).

More details here: How to obtain the rate of VAT in Magento without order object or product

• Ah right, would have come with a different answer if you said there was user input to work with! – Jonathan Hussey Nov 18 '14 at 13:12
• Sorry, I will be more accurate next time. Thanks for your input anyway! – Alan Nov 18 '14 at 15:23