Discount basket display field and How to create it

  In commerce server discount engine, if a discount is applied in shopper’s basket, you can retrieve a friendly message of that discount from OrderForm and display it to shopper. The friendly message is what we call the “basket display” field for a discount.

  How to create a basket display? if you are using Commerce Server 2002 bizdesk,  then go to campaign manager module, new discount window, in “Discount Display” section, there is a “Basket display” input for this field. (Please note, the image URL, click URL and Alternate text are for discount targeting, so-called “CSF”. They are nothing to do with OrderForm display).

  If you are using recently shipped Feature pack 1, from Discount Manager UI, there is a new discount wizard. “Basket display” input field is in the “Discount Properties” dialog. Gosh, I wish I know how to insert a picture to the blog post (doubt whether it is feasible). It will save a thousand words.

  Anyway, if you are interested in where exactly the basket display message is store, it is in Campaigns database (if using FP1, it is in Marketing database), order_discount table (mktg_order_discount table for FP1), u_disc_description column (u_disc_basketdisplay column for FP1). Since for both commerce server 2002 and FP1, the basket display are mandatory input, you should not see a null value in that column.

 

Display correct discount messages in basket

  Now the more interesting topic, from commerce server runtime, how do we display the applied discounts’ messages?  Before Feature pack 1, we need to use both the Content list in OrderForm and discounts_applied Dictionary in each basket line item.

  Data in ContentList in shopper’s OrderForm (orderform._discounts) are actually the discount data copied from runtime discount cache. In you are using commerce server BCL, you can use Microsoft.CommerceServer.Runtime.Orders.DiscountsApplied property. This property is generated by taking the discount ContentList and filtering by all applied discounts in the OrderForm (orderform._winners). In another word, those are data for applied discounts only.

   item.discounts_applied is a Dictionary containing all discounts applied to the specific basket line items. The key for the dictionary is the discount’s campaign item ID and value is the DateTime the discount getting applied.

  In fact, recently we identify an issue in commerce server retail 2002 site (shipped as SDK). This known issue is related to how to display the applied discount messages. I wrote a separate blog for that. That blog article includes the pseudo code to show basket display and the fix to the issue. Check it out if you are interested.

 

New way to display discounts in Feature pack 1

   In Commerce Server 2002 feature pack 1, we add a new feature to make this work, displaying applied discounts’ messages, a little bit easier. (The old approach still works though).

 

   For each basket line item in OrderForm, we define two SimpleLists. One is for all applied item level discounts, _itemlevel_discounts_applied. The other is for all applied order level discounts, _orderlevel_discounts_applied. Each element (which is a Dictionary) in the SimpleLists is for one specific, individual applied discount. Those two SimpleLists are in Commerce Server 2002 (without FP1) as well. You can refer to one of my previous blog articles for how to retrieve useful discount information from those SimpleLists.

 

   Now FP1 adds one new entry to each element, a.k.a., the Dictionary, of those SimpleLists. The entry’s key is discount_basket_display and the value is the friendly basket display message of the discount.

 

   So instead of going through ContentList and item.discounts_applied, you can use those two SimpleLists to display the discount messages. A sample code looks like (in VB):

 

Dim currentUserID As New System.Guid(CommerceContext.Current.UserID)

Dim cart As Microsoft.CommerceServer.Runtime.Orders.Basket

Dim cartOrderForm As Microsoft.CommerceServer.Runtime.Orders.OrderForm

Dim cartLineItem As Microsoft.CommerceServer.Runtime.Orders.LineItem

Dim pipeInfo As Microsoft.CommerceServer.Runtime.Orders.PipelineInfo

Dim discountAppliedRecords As  Microsoft.CommerceServer.Runtime.ISimpleList

Dim discountAppliedRecord As  Microsoft.CommerceServer.Runtime.IDictionary

 

Dim itemDiscountMessage As String

 

‘ get the basket

cart = CommerceContext.Current.OrderSystem.GetBasket(currentUserID)

 

‘ get the default OrderForm

cartOrderForm = cart.OrderForms(“default”)

 

‘ Run basket pipeline here, you probably need to extend your own code

‘ here, to set UserProfile and TargetingContext profile. And also your

‘ own exception handling code

 

pipeInfo = new PipelineInfo(“basket”)

cart.RunPipeline(pipeInfo)

 

 

 

‘ how to display applied discount messages. This is our focus here

 

For Each cartLineItem In cartOrderForm.LineItems

 

            itemDiscountMessage = “”

 

' retrieve information about all applied item level discounts

If Not (cartLineItem.Item("_itemlevel_discounts_applied") Is System.DBNull.Value) Then

discountAppliedRecords = CType(cartLineItem.Item("_itemlevel_discounts_applied"), ISimpleList)

For Each discountAppliedRecord In discountAppliedRecords

itemDiscountMessage = itemDiscountMessage + CType(discountAppliedRecord.Value("discount_basket_display"), String) + "<BR>"

Next

End If

 

' retrieve information about all applied order leve discounts

If Not (cartLineItem.Item("_orderlevel_discounts_applied") Is System.DBNull.Value) Then

discountAppliedRecords = CType(cartLineItem.Item("_orderlevel_discounts_applied"), ISimpleList)

For Each discountAppliedRecord In discountAppliedRecords

itemDiscountMessage = itemDiscountMessage + CType(discountAppliedRecord.Value("discount_basket_display"), String) + "<BR>"

Next

End If

 

‘ discount_message entry contains basket displays for all discounts (item level

‘ and order level) applied to this basket line item

 

cartLineItem.Item("_discounts_message") = itemDiscountMessage

Next