Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Rombouts 71 posts 265 karma points
    Aug 07, 2013 @ 11:54
    Peter Rombouts
    0

    EmailTemplate and multiple languages

    I'm currently having some issues with multi lingual templates.

    Our project has two languages; nl-NL and en-US.
    In the email template section, there are options for 'common' and both languages.

    Whatever I do, the 'Common' is always chosen, and not the language specific one.
    The Common sends the email, no problems, but it is obviously not always the correct language.

    Remark: My order does not have any languageId, and when I try to set it in code, I get the following exception:

    Type: Error | User: 0 | NodeId: -1 | 
    Comment: Error sending email using the email template: Confirmation email email for order {someguidhere} -
    Exception: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
       at System.String.Format(IFormatProvider provider, String format, Object[] args)

     

    Any ideas anyone?

    Kind regards,
    Peter Rombouts

  • Anders Burla 2560 posts 8256 karma points
    Aug 07, 2013 @ 14:38
    Anders Burla
    0

    Be sure to have the latest Tea Commerce 2.x installed - I know that there was some problems with getting the language id in older versions of 2.x.

    Try hook into the NotificationCenter.EmailTemplate.ErrorSendingMail event handler - there you get the exception and can see more details. I cant see where in TC we use a string.format in the email sending. Maybe there is an error in the razor file that you use to render the email?

    Kind regards
    Anders

  • Peter Rombouts 71 posts 265 karma points
    Aug 07, 2013 @ 14:53
    Peter Rombouts
    0

    Hi Anders,

    I'm using the default template, and I'm running the latest TeaCommerce.
    I'll try to hook into the ErrorSendingMail to see if I get more specific errors.

    Will post my results, thanks for the reply!

    Kind regards,
    Peter Rombouts

  • Peter Rombouts 71 posts 265 karma points
    Aug 09, 2013 @ 10:41
    Peter Rombouts
    0

    I've hooked into the error, and all I got was:

    Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

    Can you explain what the mailtemplate does?
    Or better; can you explain how to set another language?

    Is the 'languageId' on Order some kind of dependency (because it is empty, as it is not an required field).

    Kind regards,
    Peter Rombouts

  • Anders Burla 2560 posts 8256 karma points
    Aug 09, 2013 @ 11:34
    Anders Burla
    0

    The language id is an id of an Umbraco language. So be sure to set it to a language id that exists in Umbraco. Maybe that is the error :)

    When Tea Commerce creates an order. It will use the product identifier (nodeId) to loop ancestor or self to see if any has a hostname associated with it and then see the language of the hostname. If it find a language id it will add it to the order.

    Kind regards
    Anders

  • Peter Rombouts 71 posts 265 karma points
    Aug 09, 2013 @ 12:39
    Peter Rombouts
    0

    Hi Anders,

    The language IDs (1 and 2) are present in Umbraco.

    I'm using a product catalog, so the products do not descend from the nodes; see this example:

    As you can see, the products do not have a parent with a language.
    I'm using content pages, with 'product pickers' in them to enable the same product being used within all languages.

    Could this be part of the problem, and better yet, is there an solution?

    Duplication of products is a bit of an anti-pattern, so I would like to continue to use this setup.

    Kind regards,
    Peter Rombouts

  • Anders Burla 2560 posts 8256 karma points
    Aug 09, 2013 @ 12:53
    Anders Burla
    0

    The way we normally do multi language setup is using the master relation feature in Tea Commerce. Try and download the starter kit and see how its done with a product catalog and then a "copy" of the product at every language.

    You dont see line numer in the error or a stacktrace or something like that?

    Kind regards
    Anders

  • Peter Rombouts 71 posts 265 karma points
    Aug 09, 2013 @ 13:18
    Peter Rombouts
    0

    Hi Anders,

    This could present some problems, because not all products are available in all languages.
    If someone puts an item from the NL shop in the basket, and proceeds to EN, and adds another product, what will happen?

    What language will be chosen for the email?

    Kind regards,
    Peter Rombouts

  • Anders Burla 2560 posts 8256 karma points
    Aug 09, 2013 @ 13:56
    Anders Burla
    0

    The language id is updated everytime an order line is added. So the last order line that is added defines the language. And the email will use that id to find the hostname/culture and use that culture for the rendering of the email.

    If the EN and NL product has the same SKU, then the order line will now have a quantity of two but still use the name (NL) and properties that was copied when the order line was first added.

    Kind regards
    Anders

  • Peter Rombouts 71 posts 265 karma points
    Aug 09, 2013 @ 15:14
    Peter Rombouts
    0

    Hi Anders,

    I've resolved the issue by adding more logic to the email template.
    By setting the culture depending on the 'Model.PaymentInformation.CountryId', I have a more reliable source for my choice of language.

    After that, I can simply call the Umbraco Dictionary so I can reuse all my entries.
    Works like a charm, and we don't have to implement multiple templates.

    Thanks for your quick replies and have a great weekend!

    Kind regards,
    Peter Rombouts

  • Anders Burla 2560 posts 8256 karma points
    Aug 12, 2013 @ 10:59
    Anders Burla
    0

    Great to hear you found a way to solve you problem. Can you post some of the solution so others can benefit from the support here at the forum? And then mark that answer as the solution to the post?

    Kind regards
    Anders

  • Peter Rombouts 71 posts 265 karma points
    Aug 12, 2013 @ 12:18
    Peter Rombouts
    101

    The fix I provided works as following:

    Edit the email-template-confirmation.cshtml file, and add the following code at the start of the file:

    @using System
    @using System.Globalization
    @using System.Threading
    @using TeaCommerce.Api.Models
    @using TeaCommerce.Umbraco.Web
    @using umbraco.MacroEngines

    @inherits TeaCommerce.Umbraco.Configuration.Infrastructure.Templating.OrderContext
       
    @if ( Model.Id != null ) {
      Country paymentCountry = TC.GetCountry( Model.StoreId, Model.PaymentInformation.CountryId );
      if(paymentCountry.Id == 2 ||
         paymentCountry.Id == 3)
      {
          System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("nl-NL");
          System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");
      }
      else
      {
          System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
          System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
      }
      CountryRegion paymentCountryRegion = Model.PaymentInformation.CountryRegionId != null ? TC.GetCountryRegion( Model.StoreId, Model.PaymentInformation.CountryRegionId.Value ) : null;
      Country shippingCountry = Model.ShipmentInformation.CountryId != null ? TC.GetCountry( Model.StoreId, Model.ShipmentInformation.CountryId.Value ) : null;
      CountryRegion shippingCountryRegion = Model.ShipmentInformation.CountryRegionId != null ? TC.GetCountryRegion( Model.StoreId, Model.ShipmentInformation.CountryRegionId.Value ) : null;

      PaymentMethod paymentMethod = Model.PaymentInformation.PaymentMethodId != null ? TC.GetPaymentMethod( Model.StoreId, Model.PaymentInformation.PaymentMethodId.Value ) : null;
      ShippingMethod shippingMethod = Model.ShipmentInformation.ShippingMethodId != null ? TC.GetShippingMethod( Model.StoreId, Model.ShipmentInformation.ShippingMethodId.Value ) : null;

     

    In this example I set the culture to nl-NL on countries with ID 2 and 3, and to en-US on all other country IDs.
    You should offcourse determine for yourself which IDs should map to which culture, it is up to you.
    Our site has only two languages, so this setup was enough.

    Because of the use of these culture settings, just add all labels to the dictionary, and place them in the code like normal:

    @Dictionary["YourOrder"] @Model.OrderNumber (@Model.DateFinalized.Value.ToString( "ddd, dd MMM yyyy HH:mm" ))

    This solution will enable you to have only one template, and re-use dictionary items within the shop, Umbraco pages, and your email template.

    Kind regards,
    Peter Rombouts

Please Sign in or register to post replies

Write your reply to:

Draft