Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect currency conversion in multistore setup #285

Open
mariuszsienkiewicz opened this issue Feb 13, 2025 · 0 comments
Open

Incorrect currency conversion in multistore setup #285

mariuszsienkiewicz opened this issue Feb 13, 2025 · 0 comments
Assignees
Labels
bug Tech debt | Errors in the code pluginRangers

Comments

@mariuszsienkiewicz
Copy link

It seems that the module incorrectly calculates currencies. See the explanation below:

Let's say we have a multistore with the following configuration:

Product prices are in EUR.

  • Shop A (main one - ID = 1):
    • Default currency: EUR.
    • Example product: price 1€
  • Shop B (ID = 2):
    • Default currency: PLN (PLN exchange rate set to: 4.000000)
    • Example product: price 1€, so PrestaShop will return 4 PLN as the default price for this product.

Now, the code:

$price = self::getPrice($productId, $includeTaxes, $variantId);

The value of $price is 4.000000 in the case of Shop B.

Later, the module does this:

foreach ($currencies as $currency) {
if ($currency['deleted'] == 0 && $currency['active'] == 1) {
$convertedPrice = \Tools::convertPrice($price, $currency);
$convertedOnsalePrice = \Tools::convertPrice($onsale_price, $currency);

It iterates over all currencies (including PLN). As a result, this line:

$convertedPrice = \Tools::convertPrice($price, $currency);

Changes the price to 16.000000 (it's multiplied by 4.000000 again) - and that's the issue. I think it would be better to check if we are not iterating over the same currency, or at least ensure that it won't be recalculated again, for example like this:

// before foreach
$currentCurrencyId = \Validate::isLoadedObject($context->currency) ? (int) $context->currency->id : \Currency::getDefaultCurrencyId();

// inside foreach
if ($currency['id'] !== $currentCurrencyId) {
    $convertedPrice = \Tools::convertPrice($price, $currency);
    $convertedOnsalePrice = \Tools::convertPrice($onsale_price, $currency);
} else {
    $convertedPrice = $price;
    $convertedOnsalePrice = $onsale_price;
}

Of course, the changes above are only for visual representation of the problem; it's not a good looking/proper way to solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Tech debt | Errors in the code pluginRangers
Projects
None yet
Development

No branches or pull requests

3 participants