Bug reports Found a bug? Post it here please.
Version 7.x > Bug reports > Invoice Culture Ingored when Re-Generating an Invoice View modes: 
User avatar
Member
Member
kentico-bytix - 8/21/2013 4:28:26 AM
   
Invoice Culture Ingored when Re-Generating an Invoice
Hi

We're Currently working on a new Shop for a Customer of ours. The Shop is based in 3 languages and at the current version is 7.0.21.

To keep is short and simple. The goal is to have a multilanguage invoice. Now it should actually be Pretty simple to use macros, but how they get resolved is not really clear to me.

Let me show you 2 Parts of the Invoice:

Part 1:
{%GetResourceString("Custom.Lieferschein")%}


Part 2 will get Localized.

I searched the sourcecode how the system was retrieving the invoice and had to find this in the ShoppingCartInfoProvider.cs in the function GetOrderInvoiceInternal(ShoppingCartInfo):

string inputText = ECommerceSettings.InvoiceTemplate(ECommerceSettings.UseGlobalInvoice(cart.SiteName) ? "" : cart.SiteName);
string shoppingCartCulture = cart.ShoppingCartCulture;
cart.ShoppingCartCulture = CultureHelper.GetDefaultCulture(cart.SiteName);
MacroResolver shoppingCartResolver = ShoppingCartInfoProvider.GetShoppingCartResolver(cart);
string str = shoppingCartResolver.ResolveMacros(inputText);
cart.ShoppingCartCulture = shoppingCartCulture;



Could you explain to me why the Default system language is used to Resolve the macros and then get set back again?!? I mean how should the system be able to localize the Keys then?

Thanks for a quick reply..

Regards
Patrick

User avatar
Member
Member
kentico-bytix - 8/28/2013 4:26:18 AM
   
RE:Invoice Culture Ingored when Re-Generating an Invoice
Any Replies?

Waiting for a Reply more than 7 days now...

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 9/1/2013 6:31:48 AM
   
RE:Invoice Culture Ingored when Re-Generating an Invoice
Hi,

As we discussed separately in the email, the behavior is a consequence of the current design of CMSDesk order generation, which may not suit some scenarios, including the multilingual store and the need to regenerate the invoice in original language of the order.
However, it should work for the invoice sent via email when the Order is complete, if you enable following setting:

Use customer's culture for e-mails in E-Commerce / Configuration / Store settings / E-mails.

or do you see the behavior for both emailed and manually regenerated Invoice?

Your observation in code is anyway correct. Just before the Invoice template macro resolver is obtained, the Culture of the shopping cart created from the Order is set to the default site culture. I have already solved this issue with some other customers and forwarded their feedback to our development team. Currently, it's not considered as a bug, but we will look into it for the new version.

The explanation for current behavior is that the emails to the customer should be send in his culture, where the Invoice generated by the E-commerce administrator should be in default culture.
I know this is a limitation for certain scenarios. Our developers know about this and they will consider some improvements into next versions.

As I cannot confirm any out-of-the-box solution in near time, I offer a workaround here. Among current workaround options (with respect to the upcoming hotfixes and updates), the best way seems to be to write CustomShoppingCartInfoProvider.
The only important thing to decide is where to get the correct Culture from - the best is of course to use the original OrderCulture stored within the Order.

In short, the override of GetShoppingCartResolverInternal method will allow to specify the desired culture of the resolver.
In custom ShoppingCartInfoProvider it can look like this:
    protected override MacroResolver GetShoppingCartResolverInternal(ShoppingCartInfo cart, bool specialMacros)
{
MacroResolver result = base.GetShoppingCartResolverInternal(cart, specialMacros);
if (cart.Order != null)
{
OrderInfo origOrder = OrderInfoProvider.GetOrderInfo(cart.Order.OrderID);
if (origOrder != null)
{
result.Culture = origOrder.OrderCulture;
}
}
return result;
}

Hope this helps.
If you have any feedback to this suggestion, please feel free to share it here or via email.

Regards,
Zdenek