The ##PRODUCTLIST## macro uses a thread culture instead of shopping cart culture

   —   
If you use a template with the ##PRODUCTLIST## macro (for example an e-mail template or invoice) in your custom code, you will notice that it uses a thread culture instead of a shopping cart culture (ShoppingCartInfoObj.ShoppingCartCulture). You can follow this workaround to make it work correctly. This issue is fixed in version 6.0.
The basic approach is the following:

1. First add a new custom column to the Order object where you will store the shopping cart culture. Set its value while saving a new order in the check-out process.

2. Create a new custom macro for generating a product list. It will get the culture from the new column of the Order object and evaluate the localized strings according to this culture.

3. Then customize the GetShoppingCartInfoFromOrder method – it will set the shopping cart culture according to the value stored in the new Order column.



Ad 1.:
You can add the new column in Site manager -> Development -> System tables -> edit Ecommerce – Order -> Fields. You can set it up like this:



Then you can copy the control:

~\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartPreview.ascx

and register it as a new check-out step as in: Developing custom dialogs for check-out. Use this custom step instead of the ‘Order preview’ step.

Find the ‘ProcessStep()’ method in the new control and add this code:


try
{
// Create order
ShoppingCartInfoProvider.SetOrder(this.ShoppingCartInfoObj);

// Save customers' prefferd options
CustomerInfo ci = ShoppingCartInfoObj.CustomerInfoObj;
if (ci != null)
{
ci.CustomerPreferredCurrencyID = ShoppingCartInfoObj.ShoppingCartCurrencyID;
ci.CustomerPreferredShippingOptionID = ShoppingCartInfoObj.ShoppingCartShippingOptionID;
ci.CustomerPrefferedPaymentOptionID = ShoppingCartInfoObj.ShoppingCartPaymentOptionID;

CustomerInfoProvider.SetCustomerInfo(ci);
}

// Set order culture
ShoppingCartInfoObj.ShoppingCartCulture = CMSContext.PreferredCultureCode;


if (ShoppingCartInfoObj.OrderId > 0)
{
OrderInfo oi = OrderInfoProvider.GetOrderInfo(ShoppingCartInfoObj.OrderId);
if (oi != null)
{
oi.SetValue("OrderCulture", ShoppingCartInfoObj.ShoppingCartCulture);
oi.Update();
}
}

}



Now it will save the shopping cart culture to the Order object when it creates a new order.

Ad 2.:
You can develop a custom macro like: Macro expressions
Here you can find a sample code of CMSCustom.cs.

Ad 3.:
You can configure custom E-commerce handlers:
Custom providers overview
Using custom providers
and use Custom shopping cart info provider.

You can customize the ‘GetShoppingCartInfoFromOrder(int orderId)’ method using the following:

/// <summary>
/// Returns filled ShoppingCartInfo object from the specified order data.
/// </summary>
/// <param name="orderId">Order ID.</param>
public object GetShoppingCartInfoFromOrder(int orderId)
{
CMS.Ecommerce.ShoppingCartInfo sci = (CMS.Ecommerce.ShoppingCartInfo)ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);

//Set the OrderCulture according to ShoppingCartCulture
if (sci != null)
{
CMS.Ecommerce.OrderInfo oi = CMS.Ecommerce.OrderInfoProvider.GetOrderInfo(orderId);
sci.ShoppingCartCulture = oi.GetStringValue("OrderCulture");
}
return sci;
}


Then you can use the {#productlist#} macro instead of ##PRODUCTLIST## on your template and it will be evaluated according to the order culture. The 6.0 version handles the culture of the #PRODUCTLIST## macro properly.

-hg-



See also: Customizing invoice and e-mail templates

Applies to: Kentico CMS 5.5 R2
Share this article on   LinkedIn