Developer forum

Forum » Development » ProductInfoViewModelExtensions is missing null checks

ProductInfoViewModelExtensions is missing null checks

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

The ProductInfoViewModelExtensions is missing some null checks. I was trying to do this simple line of code and when I navigate to a Product that is Discontinued but has no Replacement Product, I get a missing ProductId error.

ProductViewModel replacementProduct = product?.ReplacementProduct?.GetProduct();

 

Here is the link to the offending file, line 10 https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_git/Dynamicweb?path=/src/77%20-%20Ecommerce/Dynamicweb.Ecommerce/ProductCatalog/ProductInfoViewModelExtensions.cs&_a=contents&version=GBmain

 

Simply validating if ProductId is not null or empty should be enough, but I haven't checked further.

 

Can this please be fixed?

 

Best Regards,

Nuno Aguiar

 

Best Regards,

Nuno Aguiar


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Sure, will add that null check:

if (settings is object && productInfo is object && !string.IsNullOrEmpty(productInfo.ProductId))
            {
                var model = ViewModelFactory.CreateView(settings, productInfo.ProductId, productInfo.VariantId);
                return model;
            }

Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Perfect, thank you Nicolai

 

You must be logged in to post in the forum