Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using InitializeTransaction() and Finalize() results variationContext being reset to default #505

Open
MichaelNielsenDK opened this issue May 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@MichaelNielsenDK
Copy link

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

@MichaelNielsenDK MichaelNielsenDK added the bug Something isn't working label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant