Show Item Discount in Transformations

Mehrdad ilchizadeh asked on December 5, 2015 08:17

Hello, i want show discount for each item in shopping cart table. discount price

i use this <%# CMS.MacroEngine.MacroResolver.Resolve("{% ECommerceContext.CurrentShoppingCart.ItemsDiscount #%}")%> but this code show price discount for all items..!!! i need for each item. this: EcommerceSite.Transformations.CheckoutShoppingCartItem

Pleas help me

Correct Answer

Martin Hejtmanek answered on December 7, 2015 15:16

Hi,

You can use property UnitTotalDiscount, or TotalDiscount of shopping cart item, so direct access would be like:

{% ECommerceContext.CurrentShoppingCart.ShoppingCartItems[0].UnitTotalDiscount %}

For the first item in shopping cart or you can use that property directly in the content transformation as shown on the default transformation in page type E-Commerce transformations - Tranformation Order_ContentTable

Here is the piece of code from it:

<td style="text-align: right; vertical-align: top;">{%(IsProductOption && !IsAccessoryProduct) ? "" : HTMLEncode((UnitPrice - UnitTotalDiscount).Format(Currency.CurrencyFormatString)) #%}</td>

See application System - Macros - Console to examine which other properties are available for the item, just browse to

ECommerceContext.CurrentShoppingCart.ShoppingCartItems[0]

And you will see the properties in the result tree

BTW, you shouldn't use MacroResolver.Resolve in the ASCX transformation, it has unnecessary overhead. Just access ECommerceContext and other properties directly with C# code

1 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.