First of all, when You use a min
and max
filter values, Your query should not be choosing between min and 9999
and between 0 and max
but You should do this:
if (!empty($data['min'])) {
$sql .= " AND p.price >= " . (int)$data['min'];
// ^^^^^ - against SQL injection!!!
}
and
if (!empty($data['max'])) {
$sql .= " AND p.price <= " . (int)$data['max'];
// ^^^^^ - against SQL injection!!!
}
Also, as mentioned in the comment, do not forget to cure Your code against SQL injection!
Now, to Your real question: It is not possible to get the taxes and calculate taxed price along with products getting in one query. But You could do this in Your model - find this part of code
foreach ($query->rows as $result) {
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}
and we will modify it this way:
foreach ($query->rows as $result) {
if (!empty($data['min'])
&& $this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')) >= $data['min']) {
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
} else if (!empty($data['max'])
&& $this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')) <= $data['max']) {
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
} else {
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}
}