cancel
Showing results for 
Search instead for 
Did you mean: 

How to get product's price in all allowed currencies?

Re: How to get product's price in all allowed currencies?

Thanks for the suggestion @Sunil Patel, but it still gets the price for the second currency wrong.

 

Outputs:

string(8) "USD - 14"
string(8) "EUR - 14"
string(10) "EUR - 9.89"
string(10) "USD - 9.89"

So even the whole reload of the products doesn't help.

It feels like there is some object inside which is not invalidated (or recreated?) by ObjectManager and it always returns the price which was fetched first.

Re: How to get product's price in all allowed currencies?

@algolia

 

magento 2 always provide final price as you specified in backend you need to convert into that currency.

 

 

$product = $product->getFinalPrice(); // that price into base currency // for you it is EUR
$store =$product->getStore();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$priceCurrencyObject = $objectManager->get('Magento\Framework\Pricing\PriceCurrencyInterface');
$rate = $priceCurrencyObject->convert($price, $store, 'USD');
echo $rate;exit; // price into usd 

Hope it will work for you, i checked and it is working.

 

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to get product's price in all allowed currencies?

Hello @Sunil Patel,

 

I made it work. My base price is USD so the $product->getPrice(); returns price in USD. Then I can convert to EUR and it works OK. So far everything's good!

 

However there is one issue with that approach - catalog price rules.

When I run $product->getFinalPrice(); it won't get the price affected by catalog price rules - it will get just the price set to the product.

To get the price affected by catalog price rule I need to run $product->getPriceInfo()->getPrice('final_price')->getValue();, but in this case the price is already converted to EUR and I don't have any reliable way on how to convert it to USD.

 

Do you know how to make $product->getFinalPrice(); to return the price affected by catalog price rules?

Re: How to get product's price in all allowed currencies?

I ran into exactly the same problem that you described. Can you please tell me how you solved it?