ILocalizationContext allways en-GB in pipeline tasks
Hey Ucommerce team
I am trying to send and orders shipped email when the order is moved from "New Order" to "Completed Order" The pipeline is running as it should but i am using Deperency Injection to get my LocalizationContext but it is allways en-GB and the only language that is added to umbraco is danish.
I am using a pipeline task as below
public class SendOrderCompletedEmailTask : IPipelineTask<PurchaseOrder>
{
private IEmailService _emailService;
private ILocalizationContext _localizationContext;
public SendOrderCompletedEmailTask(IEmailService emailService, ILocalizationContext localizationContext)
{
_emailService = emailService;
_localizationContext = localizationContext;
}
public PipelineExecutionResult Execute(PurchaseOrder subject)
{
if (subject != null)
{
try
{
var emailProfile = SiteContext.Current.CatalogContext.CurrentCatalogGroup.EmailProfile;
var queryStringParameters = new Dictionary<string, string>();
queryStringParameters.Add("orderGuid", subject.OrderGuid.ToString());
queryStringParameters.Add("customerId", subject.Customer.CustomerId.ToString());
_emailService.Send(_localizationContext, emailProfile, "OrderShipped", new MailAddress("[email protected]"), queryStringParameters);
//_emailService.Send(_localizationContext, emailProfile, "OrderShipped", new MailAddress(subject.BillingAddress.EmailAddress), queryStringParameters);
return PipelineExecutionResult.Success;
}
catch (Exception ex)
{
var t = ex;
return PipelineExecutionResult.Error;
}
}
return PipelineExecutionResult.Error;
}
}
Is it because i cant inject the localization context ?
I have now tryed to change my code to reflect the SendEmailTask In Ucommerce.Pipelines.Common
So instead of LocalizationContext i am now using CommerceConfigurationProvider but as funny as it sounds it wants to show the email in US format and not en-GB Where are these data stored ?
Updated Code
public class SendOrderCompletedEmailTask : IPipelineTask<PurchaseOrder>
{
private IEmailService _emailService;
private CommerceConfigurationProvider _commerceConfiguration;
public SendOrderCompletedEmailTask(IEmailService emailService, CommerceConfigurationProvider commerceConfiguration)
{
_emailService = emailService;
_commerceConfiguration = commerceConfiguration;
}
public PipelineExecutionResult Execute(PurchaseOrder subject)
{
if (subject != null)
{
try
{
var emailProfile = subject.ProductCatalogGroup.EmailProfile;
CustomGlobalization customGlobalization = new CustomGlobalization(_commerceConfiguration);
customGlobalization.SetCulture(new CultureInfo(subject.CultureCode ?? customGlobalization.DefaultCulture.ToString()));
var queryStringParameters = new Dictionary<string, string>();
queryStringParameters.Add("orderGuid", subject.OrderGuid.ToString());
queryStringParameters.Add("customerId", subject.Customer.CustomerId.ToString());
_emailService.Send((ILocalizationContext)customGlobalization, emailProfile, "OrderShipped", new MailAddress("[email protected]"), queryStringParameters);
//_emailService.Send(_localizationContext, emailProfile, "OrderShipped", new MailAddress(subject.BillingAddress.EmailAddress), queryStringParameters);
return PipelineExecutionResult.Success;
}
catch (Exception ex)
{
var t = ex;
return PipelineExecutionResult.Error;
}
}
return PipelineExecutionResult.Error;
}
}
The pipelines will actually use the culture code stored on the order itself. The reason for this is that you might want to send out e-mail in a different context than the user was originally in, such as order processing, and so uCommerce will track the origianal culture code on the order and use that.
You can change the culture on the order if you want it to be something else.
Thx for the reply, That was exatly was i was expecting that the order it self knows when culture it was given in. But what determines this, is it the culture set on the website and then what happens if u use "Default" as selected host name in the shop configuration ?
and last but not least u say i can change the culture, where do i do that ?
It will actually always use the culture specified on the thread. So it will either be the culture you set up on whatever node the user is visiting or the default provided by ASP.NET and ultimately the browser culture.
ILocalizationContext allways en-GB in pipeline tasks
Hey Ucommerce team
I am trying to send and orders shipped email when the order is moved from "New Order" to "Completed Order"
The pipeline is running as it should but i am using Deperency Injection to get my LocalizationContext but it is allways en-GB and the only language that is added to umbraco is danish.
I am using a pipeline task as below
Is it because i cant inject the localization context ?
Regards Troels
I have now tryed to change my code to reflect the SendEmailTask In Ucommerce.Pipelines.Common
So instead of LocalizationContext i am now using CommerceConfigurationProvider but as funny as it sounds it wants to show the email in US format and not en-GB
Where are these data stored ?
Updated Code
Hi Troels,
The pipelines will actually use the culture code stored on the order itself. The reason for this is that you might want to send out e-mail in a different context than the user was originally in, such as order processing, and so uCommerce will track the origianal culture code on the order and use that.
You can change the culture on the order if you want it to be something else.
Hey Søren
Thx for the reply, That was exatly was i was expecting that the order it self knows when culture it was given in. But what determines this, is it the culture set on the website and then what happens if u use "Default" as selected host name in the shop configuration ?
and last but not least u say i can change the culture, where do i do that ?
//Troels
for someone els stumbling over this post u can set default culture in config under :
<commerce>
<catalogConfiguration defaultCultureCode="en-US" enforceCategoryNameUniquenessWithinCatalogs="true" />
//Troels
It will actually always use the culture specified on the thread. So it will either be the culture you set up on whatever node the user is visiting or the default provided by ASP.NET and ultimately the browser culture.
Hope this helps.
is working on a reply...