Skip to content

Commit

Permalink
Fixed null reference exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarincev committed Oct 27, 2017
1 parent e86804f commit 2449d77
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions VirtoCommerce.Storefront/Domain/Catalog/CatalogConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,15 @@ public virtual catalogDto.ProductSearchCriteria ToProductSearchCriteriaDto(Produ
result.Terms.Add(string.Concat("vendor:", criteria.VendorId));
}
// Add user groups to terms
if (workContext.CurrentUser.Contact != null)
var contact = workContext.CurrentUser?.Contact?.Value;
if (contact != null && !contact.UserGroups.IsNullOrEmpty())
{
var contact = workContext.CurrentUser.Contact.Value;
if (contact != null && !contact.UserGroups.IsNullOrEmpty())
if (result.UserGroups == null)
{
if (result.UserGroups == null)
{
result.UserGroups = new List<string>();
}
//search products with user_groups defined in customer
result.UserGroups.Add("user_groups:" + string.Join(",", contact.UserGroups));
result.UserGroups = new List<string>();
}
//search products with user_groups defined in customer
result.UserGroups.AddRange(contact.UserGroups);
}

return result;
Expand Down Expand Up @@ -296,15 +293,15 @@ public virtual catalogDto.CategorySearchCriteria ToCategorySearchCriteriaDto(Cat
Take = criteria.PageSize,
ResponseGroup = ((int)criteria.ResponseGroup).ToString(),
};
var contact = workContext.CurrentUser.Contact.Value;
var contact = workContext.CurrentUser?.Contact?.Value;
if (contact != null && !contact.UserGroups.IsNullOrEmpty())
{
if (result.UserGroups == null)
{
result.UserGroups = new List<string>();
}
//search categories with user_groups defined in customer
result.UserGroups.Add("user_groups:" + string.Join(",", contact.UserGroups));
result.UserGroups.AddRange(contact.UserGroups);
}

return result;
Expand Down

0 comments on commit 2449d77

Please sign in to comment.