public virtual catalogDto.ProductSearchCriteria ToProductSearchCriteriaDto(ProductSearchCriteria criteria, WorkContext workContext) { var result = new catalogDto.ProductSearchCriteria { SearchPhrase = criteria.Keyword, LanguageCode = criteria.Language?.CultureName ?? workContext.CurrentLanguage.CultureName, StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, Outline = criteria.Outline, Currency = criteria.Currency?.Code ?? workContext.CurrentCurrency.Code, Pricelists = workContext.CurrentPricelists.Where(p => p.Currency.Equals(workContext.CurrentCurrency)).Select(p => p.Id).ToList(), PriceRange = criteria.PriceRange?.ToNumericRangeDto(), Terms = criteria.Terms.ToStrings(), Sort = criteria.SortBy, Skip = criteria.Start, Take = criteria.PageSize, ResponseGroup = ((int)criteria.ResponseGroup).ToString(), }; // Add vendor id to terms if (!string.IsNullOrEmpty(criteria.VendorId)) { if (result.Terms == null) { result.Terms = new List <string>(); } result.Terms.Add(string.Concat("vendor:", criteria.VendorId)); } return(result); }
public static catalogDto.ProductSearchCriteria ToProductSearchCriteriaDto(this ProductSearchCriteria criteria, WorkContext workContext) { var result = new catalogDto.ProductSearchCriteria { SearchPhrase = criteria.Keyword, LanguageCode = criteria.Language?.CultureName ?? workContext.CurrentLanguage.CultureName, StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, Outline = criteria.Outline, Currency = criteria.Currency?.Code ?? workContext.CurrentCurrency.Code, Pricelists = workContext.CurrentPricelists.Where(p => p.Currency.Equals(workContext.CurrentCurrency)).Select(p => p.Id).ToList(), PriceRange = criteria.PriceRange?.ToNumericRangeDto(), Terms = criteria.Terms.ToStrings(), Sort = criteria.SortBy, Skip = criteria.Start, Take = criteria.PageSize, ResponseGroup = ((int)criteria.ResponseGroup).ToString(), IsFuzzySearch = criteria.IsFuzzySearch, }; // Add vendor id to terms if (!string.IsNullOrEmpty(criteria.VendorId)) { if (result.Terms == null) { result.Terms = new List <string>(); } result.Terms.Add(string.Concat("vendor:", criteria.VendorId)); } // Add user groups to terms var contact = workContext.CurrentUser?.Contact; if (contact != null && !contact.UserGroups.IsNullOrEmpty()) { if (result.UserGroups == null) { result.UserGroups = new List <string>(); } //search products with user_groups defined in customer result.UserGroups.AddRange(contact.UserGroups); } return(result); }