warren
(Warren Buckley)
April 17, 2026, 2:34pm
1
Hello
I am looking at the documentation for Implementing a Currency Switcher
Question
The partial has a form POST submission to a controller
Am I missing something or a reference to this in a previous article perhaps?
@using (Html.BeginUmbracoForm("ChangeCountry", "Culture", FormMethod.Post, new { @name = "changeCountryForm" }))
But currently from this page I have no idea what happens inside the controller method and what it should do in order to switch the currency of the order.
Cheers,
Warren
EssCee
(SC)
April 17, 2026, 3:07pm
3
Not sure if this is what your after/or helps
warren
(Warren Buckley)
April 17, 2026, 3:20pm
4
Thanks that did indeed help @EssCee and for anyone wanting to know/see the code directly in the post here and save yourself a click then its here…
CultureSurfaceController.cs
public class CultureSurfaceController : SurfaceController
{
private readonly IUmbracoCommerceApi _commerceApi;
public CultureSurfaceController(
IUmbracoContextAccessor umbracoContextAccessor,
IUmbracoDatabaseFactory databaseFactory,
ServiceContext services,
AppCaches appCaches,
IProfilingLogger profilingLogger,
IPublishedUrlProvider publishedUrlProvider,
IUmbracoCommerceApi commerceApi)
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
{
_commerceApi = commerceApi;
}
[HttpPost]
public async Task<IActionResult> ChangeCountry(ChangeCountryDto changeCountryDto)
{
var store = CurrentPage.GetStore();
var country = await _commerceApi.GetCountryAsync(store.Id, changeCountryDto.CountryIsoCode);
var currency = await _commerceApi.GetCurrencyAsync(country.DefaultCurrencyId.Value);
await _commerceApi.SetDefaultPaymentCountryAsync(store.Id, country);
await _commerceApi.SetDefaultShippingCountryAsync(store.Id, country);
await _commerceApi.SetDefaultCurrencyAsync(store.Id, currency);
var currentOrder = await _commerceApi.GetCurrentOrderAsync(store.Id);
if (currentOrder != null)
{
await _commerceApi.Uow.ExecuteAsync(async uow =>
{
var writableOrder = await currentOrder.AsWritableAsync(uow)
.ClearPaymentCountryRegionAsync()
.ClearShippingCountryRegionAsync()
.SetCurrencyAsync(currency.Id);
await _commerceApi.SaveOrderAsync(writableOrder);
uow.Complete();
});
}
return RedirectToCurrentUmbracoPage();
}
}
ChangeCountryDto.cs
public class ChangeCountryDto
{
public string CountryIsoCode { get; set; }
}
1 Like