Soteriologist

I'm working with the StarterSite.

I've customized my own OrderDetail control based off the OrderDetail source code.

I've created an extra column in the line item table that's right below the address area in my control. Now I want to fill that column with a custom property that we've given our products. How do I do this

I've tried:

Code Snippet

this.RenderTableCell(writer, lineItem["SkuID"].ToString());

I receive this error: "Object reference not set to an instance of an object".

So how do I add this data to my collection of lineItems




Re: Commerce Server 2007 Custom lineitem colum on the OrderDetail control on the StarterSite

Phillip U

Without a full code sample I can only guess that you've put the line in the wrong place. I would recommend adding the code to RenderLineItem. And don't forget to add a placeholder or colspan in RenderDiscount or your table will be messed up.



Re: Commerce Server 2007 Custom lineitem colum on the OrderDetail control on the StarterSite

Soteriologist

I have it inside render line item like so:

Code Snippet

protected void RenderLineItem(HtmlTextWriter writer, LineItem lineItem, bool alternateRow)

{

if (writer == null)

{

throw new ArgumentNullException("writer");

}

if (lineItem == null)

{

throw new ArgumentNullException("lineItem");

}

string rowClass = alternateRow "Even" : "OddRow";

writer.AddAttribute(HtmlTextWriterAttribute.Class, rowClass);

writer.RenderBeginTag(HtmlTextWriterTag.Tr);

{

string quantityString = lineItem.Quantity.ToString("#", CultureInfo.CurrentCulture);

string quantityClass = "quantity";

if (lineItem.InventoryCondition.Equals(InventoryCondition.OutOfStock))

{

quantityString = rm.GetString("OutOfStock");

quantityClass = "OutOfStock";

}

decimal preDiscountPrice = lineItem.ExtendedPrice + lineItem.LineItemDiscountAmount + lineItem.OrderLevelDiscountAmount;

this.RenderTableCell(writer, lineItem["SkuID"].ToString());

this.RenderTableCell(writer, String.Empty);

this.RenderTableCell(writer, quantityString, quantityClass);

RenderLineItemDisplayName(writer, lineItem);

this.RenderTableCell(writer, CurrencyConversion.Active.ConvertAndFormat(lineItem.ListPrice), CurrencyClassName);

this.RenderTableCell(writer, CurrencyConversion.Active.ConvertAndFormat(preDiscountPrice), CurrencyClassName);

}

writer.RenderEndTag();

foreach (DiscountApplicationRecord discount in lineItem.ItemLevelDiscountsApplied)

{

writer.AddAttribute(HtmlTextWriterAttribute.Class, rowClass);

RenderDiscount(writer, discount);

}

foreach (DiscountApplicationRecord discount in lineItem.OrderLevelDiscountsApplied)

{

writer.AddAttribute(HtmlTextWriterAttribute.Class, rowClass);

RenderDiscount(writer, discount);

}

}






Re: Commerce Server 2007 Custom lineitem colum on the OrderDetail control on the StarterSite

Phillip U

Will all line items always have a "SkuID" And are you sure you don't mean "_product_SkuID" Attribute names added using the catalog manager are prefixed with "_product_" in the line item.

I have a similar situation in an installation where a custom attribute is not always present depending on the product. I use try...catch to populate a local variable with the optional line item attribute or set it to a default if try fails. Then I write the variable using RenderTableCell.




Re: Commerce Server 2007 Custom lineitem colum on the OrderDetail control on the StarterSite

Soteriologist

I tried what you suggested:

Code Snippet

this.RenderTableCell(writer, lineItem["_product_SkuID"].ToString());

I get the same object error.

When I try the strongly-typed property of "ProductID":

Code Snippet

this.RenderTableCell(writer, lineItem.ProductID.ToString());

I get this error:

'Microsoft.CommerceServer.Runtime.Orders.LineItem' does not contain a definition for 'ProductID'






Re: Commerce Server 2007 Custom lineitem colum on the OrderDetail control on the StarterSite

Phillip U

Here is a snippet from a solution I used based on the StarterSite CommerceComponents.dll:

string isEvent = null;
try
{
isEvent = lineItem["_product_IsEvent"].ToString();
}
catch
{
isEvent = "No";
}

RenderTableCell(writer, isEvent);

My RenderLineItem procedure is not as customized as yours (all I did was literally add the code above directly after the RenderLineItemDisplayname(writer, lineItem) line in the RenderLineItem procedure in BasketDetail.cs). As far as the weakly-type property goes goes, mine fails if I don't first prepare for it not being present. In my case, a try...catch works. Regarding the strong-typed ProductId, note that the final "d" is lowercase - your code sample is uppercase.

The IsEvent attribute was created using the catalog schema manager and catalog manager and it is a string value that contains a Yes or No but it is not included for every product definition. Just wanted you to have some background. Hope this helps.




Re: Commerce Server 2007 Custom lineitem colum on the OrderDetail control on the StarterSite

Soteriologist

Thank God for your wonderful eyes... bloody upper-case "D"!!!!

And thank you for the try/catch code snippet, it works great.

Here's my situation so far:

I CAN now get ProductId to show on the final page... that's a great step!!!

I can't get SkuId to show. This is really strange to me because:

  • NOW I know to look really close to make sure that I spell it correctly
  • It's a built in property NOT a custom property
  • I've tried referring to it both as strongly-typed and weakly-typed
  • I tried your suggestion of referring to it as weakly-typed and concatenating "_product_"

I've also tried making reference to custom properties and none work.

I'm thinking that these values aren't part of the basket/lineItem dataset; which makes me wonder how we can make them part of it

Thanks for all of your help so far.






Re: Commerce Server 2007 Custom lineitem colum on the OrderDetail control on the StarterSite

Phillip U

Sorry, I don't use SKUs in my solution. Looking into it, SKUs are properties of product variants. Are you using variants Or have you somehow managed to use them in your base properties for a product And if so, how

If you are using variants, then you probably need to use your lineItem to look up the proper variant and get the SKU value from there. Then you can write it into your basketdetail. Alternatively, you could modify your basketpage.cs to have the SKU looked up and written into the line item when it's added into your cart so that you don't have to look it up everytime a basket is rendered, only when an item is added to the cart.

HTH.