Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions ps_facetedsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,27 @@ public function indexProductPrices($idProduct, $smart = true)
'GROUP BY id_product, tr.id_country'
);

if (empty($taxRatesByCountry) || !Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')) {
$shopCountries = Country::getCountriesByIdShop($idShop, $this->getContext()->language->id);
$taxCountries = array_filter($shopCountries, function ($country) {
return $country['active'];
});
$taxRatesByCountry = array_map(function ($country) {
return [
// When tax is not applied to indexed prices, drop the per-country tax rates entirely.
if (!Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')) {
$taxRatesByCountry = [];
}

// Always index every active country of the shop. Countries that have no specific tax
// rule for this product (or when the "use tax" option is off) are indexed with a 0% rate.
// Without this, the price sort - an INNER JOIN on layered_price_index.id_country - returns
// no products at all for customers whose country was not indexed. This makes the
// with-tax-rules path consistent with the path already used for products without any tax
// rule. See https://github.com/PrestaShop/ps_facetedsearch/issues/1206
$indexedCountryIds = array_column($taxRatesByCountry, 'id_country');
$shopCountries = Country::getCountriesByIdShop($idShop, $this->getContext()->language->id);
foreach ($shopCountries as $country) {
if (!empty($country['active']) && !in_array($country['id_country'], $indexedCountryIds)) {
$taxRatesByCountry[] = [
'rate' => 0,
'id_country' => $country['id_country'],
'iso_code' => $country['iso_code'],
];
}, $taxCountries);
}
}

$productMinPrices = $this->getDatabase()->executeS(
Expand Down
Loading