Developer forum

Forum » Development » Observation: Potential null reference issue when displaying orders

Observation: Potential null reference issue when displaying orders

Reynir Viðar Ingason
Reply

Hey there,

 

I have been working with a rapido full installation and noticed as slight quirk.
After I completed an order and tried to view it in ecommerce module in the backend I got a null reference displaying.

The issue appears to be because there was no stock location set on the product I had purchased(PROD100) an so the GetStockInfo function thrw an exception.
I fixed it by setting the stock location which wasn't so bad but there are two things I would usggest for a better experience:

1. Have the Rapido Full Database delivered with stocklocations set og most products, if not all.

2. Add a null check on the output of GetStockLocationById in the following code
(located in ...\Dynamicweb.Admin-9.6\Dynamicweb.Admin\Admin\Module\eCom_Catalog\dw7\edit\UCOrderEdit.ascx.vb):

Private Shared Sub GetStockInfo(ol As OrderLine, ByRef stockLocationName As String, ByRef unitName As String)
    Dim unitId As String = If(String.IsNullOrEmpty(ol.UnitId), ol.Product.DefaultUnitId, ol.UnitId)

    Dim productUnits As IEnumerable(Of StockUnit) = StockUnit.GetProductStockUnits(ol.ProductId, ol.ProductVariantId)
    If Not productUnits.Any() AndAlso Not String.IsNullOrEmpty(ol.ProductVariantId) AndAlso String.IsNullOrEmpty(ol.Product.VariantId) Then
        productUnits = StockUnit.GetProductStockUnits(ol.Product.Id, ol.Product.VariantId)
    End If
    If productUnits.Any() Then
        Dim stockUnit As StockUnit = productUnits.FirstOrDefault(Function(su) String.Equals(su.UnitId, unitId, StringComparison.OrdinalIgnoreCase))
        If stockUnit IsNot Nothing Then
            stockLocationName = StockLocation.GetStockLocationById(stockUnit.StockLocationId).Name
        End If
     End If

     If Not String.IsNullOrEmpty(unitId) Then
         Dim varOpt As VariantOption = Ecommerce.Services.VariantOptions.GetVariantOption(unitId, Common.Context.LanguageID)
         If varOpt IsNot Nothing Then
             unitName = varOpt.Name
         End If
     End If
End Sub

Replies

 
Olga Shedko Dynamicweb Employee
Olga Shedko
Reply

Hello Reynir,

This bug was fixed within TFS # 65841. Will be available with next hotfix release.

Thank you.

Best regards,

Olga | QA

 

You must be logged in to post in the forum