BV Commerce Forum
»
BV Commerce Support
»
General Support
»
How do I programatically access Type Properties from an Order's line item?
Rank: Member
Joined: 10/17/2006(UTC) Posts: 66
|
I have defined several products with custom property types, like "Color" and "InternalProductCode". In the checkout.aspx, I am looping through the line items in the basket with code like: Code: Dim lineItem as BVSoftware.Bvc5.Core.Orders.LineItem For Each lineItem in Basket.Items
'*** Here, I would like to access the custom property types of the lineItem
How can I get to the values of the custom property types from the line Item? I have looked at the lineItem.AssociatedProduct and everything else I can think of in the debugger. But can't find the right property. Any times?
|
|
|
|
Rank: Member
Joined: 11/5/2003(UTC) Posts: 2,136
Was thanked: 1 time(s) in 1 post(s)
|
Does this help? Code: ProductType pt = ProductType.FindByBvin(lineitem.AssociatedProduct.ProductTypeId); List<ProductProperty> props = ProductType.FindPropertiesForType(pt.Bvin);
foreach (ProductProperty property in props) { string value = InternalProduct.GetPropertyValue(lineitem.AssociatedProduct.Bvin, property.Bvin); }
|
|
|
|
|
Rank: Member
Joined: 10/17/2006(UTC) Posts: 66
|
Nice. Seems like that would be a handy collection to hang off the LineItem object. There is one problem, though. If the value is a dropdown list item, it looks like I get a BVIN style number, like "1212313-123123-123123-12312312313". How do I look up the string value for that? Just for posterity, here is the code in VB: Code: Dim pt As ProductType = ProductType.FindByBvin(lineItem.AssociatedProduct.ProductTypeId) Dim props As System.Collections.Generic.List(Of ProductProperty) = ProductType.FindPropertiesForType(pt.Bvin) Dim pp As ProductProperty For Each pp In props Dim value As String = InternalProduct.GetPropertyValue(lineItem.AssociatedProduct.Bvin, pp.Bvin) Next
Thanks.
|
|
|
|
Rank: Member
Joined: 10/17/2006(UTC) Posts: 66
|
Here is the answer to the second part of the question: If the product type has a list of choices, then Internal.GetPropertyValue(...) will return the bvin of a ProductPropertyChoice object. The ProductPropertyChoice collection must then be searched. The following function handles the details: Code: ''' <summary> ''' Lookup the value of a line item's product type by key. ''' </summary> ''' <param name="lineItem"></param> ''' <param name="key"></param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function GetProductTypeValue(ByRef lineItem As LineItem, ByVal key As String) As String
Dim pt As ProductType = ProductType.FindByBvin(lineItem.AssociatedProduct.ProductTypeId) Dim props As System.Collections.Generic.List(Of ProductProperty) = ProductType.FindPropertiesForType(pt.Bvin) Dim pp As ProductProperty For Each pp In props If pp.DisplayName = key Then Dim ppc As System.Collections.Generic.List(Of ProductPropertyChoice) = ProductPropertyChoice.FindByPropertyID(pp.Bvin) If ppc.Count = 0 Then Return InternalProduct.GetPropertyValue(lineItem.AssociatedProduct.Bvin, pp.Bvin) Else '*** For items with choices, the property value contains the BVIN of the choice... Dim bvin As String bvin = InternalProduct.GetPropertyValue(lineItem.AssociatedProduct.Bvin, pp.Bvin) For Each choice As ProductPropertyChoice In ppc If choice.Bvin = bvin Then Return choice.ChoiceName End If Next Return "" End If End If Next
'*** Not found. Return ""
End Function
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.