Umbraco.Commerce.Issues
Umbraco.Commerce.Issues copied to clipboard
Using InitializeTransaction() and Finalize() results variationContext being reset to default
When doing something like this
var testVariationContextBefore = _variationContextAccessor.VariationContext?.Culture;
_umbracoCommerceApi.Uow.Execute(uow =>
{
var order = _umbracoCommerceApi.GetCurrentOrder(storeId)
.AsWritable(uow);
//Finalize order
order.InitializeTransaction();
order.Finalize(order.TotalPrice, Guid.NewGuid().ToString("N"), PaymentStatus.Authorized);
_umbracoCommerceApi.SaveOrder(order);
uow.Complete();
});
var testVariationContextAfter = _variationContextAccessor.VariationContext?.Culture;
And being on e.g. an english variant, the testVariationContextBefore
variable will have a value of en
, but testVariationContextAfter
will have a value of da
, as danish is the default variant.
Something is happening in InitializeTransaction()
and/or Finalize()
so variationContext is set to default.
If any redirection happen after finalizing, for example to a receipt page, the user will be redirected to the incorrect variant.
A temporary work around is fetch the variationContext prior to calling InitializeTransaction()
and Finalize()
, and then set it before redirections, so something like this
var currentVariationContext = _variationContextAccessor.VariationContext?.Culture;
_umbracoCommerceApi.Uow.Execute(uow =>
{
var order = _umbracoCommerceApi.GetCurrentOrder(storeId)
.AsWritable(uow);
//Finalize order
order.InitializeTransaction();
order.Finalize(order.TotalPrice, Guid.NewGuid().ToString("N"), PaymentStatus.Authorized);
_umbracoCommerceApi.SaveOrder(order);
uow.Complete();
});
_variationContextAccessor.VariationContext = new VariationContext(currentVariationContext);
return RedirectToUmbracoPage(receiptPage);
Umbraco 13.1.1 Umbraco Commerce 13.1.3