0

I currently have

  • magento. 2.4.3
  • A store with currencyies allowed: [EUR,GBP,CHF,DKK,SEK].
  • A product, 239.90 euro including vat in EUR (the base currency).
  • DKK as my currency in the frontend of the store store (and thus in my session / cookie)

In my custom module, called via ajax from my knockout component, i do the following for a configurable product:

$productRegularPrice = $product->getPriceInfo()->getPrice('regular_price')->getValue();
$productFinalPrice = $product->getPriceInfo()->getPrice('final_price')->getValue();

Result:

$productRegularPrice = 239.90; (the euro price)
$productFinalPrice = 1785.03; (the price according to my session)

Why does the 'regular price' return the non-converted price, and the final_price the converted price?

It get's stranger: if i request this for a simple product

$productRegularPrice = $product->getPriceInfo()->getPrice('regular_price')->getValue();
$productFinalPrice = $product->getPriceInfo()->getPrice('final_price')->getValue();

Both calls return the foreign currency price.

For my requirement, i need the regular price ($product->getData('price')) and the final price ( the lowest of [$price, special_price , catalog_rule_price]) in the store's base currency. I'm thinking of juist building a something that skips the model and retrieves these values directly, however, that's the dirty solution and i prefer doing it the right way.

What i already tried Forcing the currency by setting the current currency via the storemanager, and setting it back to the old value after retrieving the prices.

$this->storeManager->getStore()->setCurrentCurrencyCode($code);

This works, but seems to cause all kinds of strange caching problems (i think in the repository).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.