Currencydropdoenlist - DisplayPrice in MVC doesn't chnage
Hi Team,
I have created one MVC widget to show product information, in that I have to show price too.
I tried using following properties to display price value:
DisplayPrice
DisplayPriceFormatted
DisplayPriceWithVatAndSale
DisplayTaxInPrice
Price
But when I change the Currencydropdoenlist to some other currency, price value doesn't change it remains as it is.
Whereas the price value which is displayed using Sitefinity product list template changes successfully.
Please let me know how to change the price on currency change using MVC widget.
Regards,
Mateen
Hi
You can use the eCommerce helpers in order to convert a price to another currency and format it:
var priceUk = EcommerceCurrencyFormatter.ToCurrencyString(50,
"en"
,
"GBP"
);
var priceEu = EcommerceCurrencyFormatter.ToCurrencyString(50,
"de"
,
"EUR"
);
var priceUsa = EcommerceCurrencyFormatter.ToCurrencyString(50,
"en"
,
"USD"
);
EcommerceExchangeRateConverter exchangeRateUtilities =
new
EcommerceExchangeRateConverter();
var convPriceUk = exchangeRateUtilities.ConvertPrice(50,
"GBP"
);
var convPriceEu = exchangeRateUtilities.ConvertPrice(50,
"EUR"
);
var convPriceUsa = exchangeRateUtilities.ConvertPrice(50,
"USD"
);
Thanks Nikola,
Through this code price is getting converted successfully.
Can you please tell how to get current selected currency name through code to pass as a parameter to EcommerceExchangeRateConverter e.g "USD" or "EUR".
Thanks
Hi
You can use the following code snippet to get all currencies. This way you can build your own dropdown currency selector, since I think this way will be easier to get the selected currency. Moreover, you can update the products price depending on the currency using ajax, since the default currency control makes a postback.
List<
string
> currencies = EcommerceSettings.Currencies.SupportedCurrencies.Values.Where(ca => ca.IsActive).Select(ca => ca.Name).ToList();
$(
".sfcurrenciesDropDownList option[selected]"
).val()
Hi Nikola,
I am facing the same issue.
How can I get the selected currency of default currency selector in code instead of script?
By using your code I am able to fetch the active currencies but not the currently selected one.
Regards,
Chaitanya
Hi Chaitanya,
Actually, you can get the selected currency from the cookie that is set when the currency selector is set and the currency is changed. The cookie is 'selectedDisplayCurrency' and the value is the currency in format "GBP" or "EUR" for instance. You can try read the value from the cookie, if it is not set, use the default currency.
Regards,
Nikola Zagorchev
Telerik
Thanks Nikola
It is working fine now :)
Hello
I am glad the issue is resolved.
Regards,
Nikola Zagorchev
Telerik
Okay so you can get the current currency from the cookie and I assume you can set the cookie value, but how do you actually change the selected currency in C#?