protected virtual void ConvertPagingSorting(CatalogSearchQuery query, RouteData routeData, string origin)
        {
            var index = Math.Max(1, GetValueFor <int?>("i") ?? 1);
            var size  = GetPageSize(query, routeData, origin);

            query.Slice((index - 1) * size, size);

            var orderBy = GetValueFor <ProductSortingEnum?>("o");

            if (orderBy == null || orderBy == ProductSortingEnum.Initial)
            {
                if (origin.Equals("Search/Search"))
                {
                    orderBy = _searchSettings.DefaultSortOrder;
                }
                else
                {
                    orderBy = _catalogSettings.DefaultSortOrder;
                }
            }

            query.CustomData["CurrentSortOrder"] = orderBy.Value;

            query.SortBy(orderBy.Value);
        }
        protected virtual List <RuleValueSelectListOption> SearchProducts(RuleOptionsResult result, string term, int skip, int take)
        {
            List <RuleValueSelectListOption> products;
            var fields = new List <string> {
                "name"
            };

            if (_searchSettings.Value.SearchFields.Contains("sku"))
            {
                fields.Add("sku");
            }
            if (_searchSettings.Value.SearchFields.Contains("shortdescription"))
            {
                fields.Add("shortdescription");
            }

            var searchQuery = new CatalogSearchQuery(fields.ToArray(), term);

            if (_searchSettings.Value.UseCatalogSearchInBackend)
            {
                searchQuery = searchQuery
                              .Slice(skip, take)
                              .SortBy(ProductSortingEnum.NameAsc);

                var searchResult = _catalogSearchService.Value.Search(searchQuery);
                result.HasMoreData = searchResult.Hits.HasNextPage;

                products = searchResult.Hits
                           .Select(x => new RuleValueSelectListOption
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name,
                    Hint  = x.Sku
                })
                           .ToList();
            }
            else
            {
                var query = _catalogSearchService.Value.PrepareQuery(searchQuery);

                var pageIndex = take == 0 ? 0 : Math.Max(skip / take, 0);
                result.HasMoreData = (pageIndex + 1) * take < query.Count();

                products = query
                           .Select(x => new RuleValueSelectListOption
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name,
                    Hint  = x.Sku
                })
                           .OrderBy(x => x.Text)
                           .Skip(() => skip)
                           .Take(() => take)
                           .ToList();
            }

            return(products);
        }
        protected virtual async Task ConvertPagingSortingAsync(CatalogSearchQuery query, string origin)
        {
            var index = Math.Max(1, GetValueFor <int?>("i") ?? 1);
            var size  = await GetPageSize(query, origin);

            query.Slice((index - 1) * size, size);

            var orderBy = GetValueFor <ProductSortingEnum?>("o");

            if (orderBy == null || orderBy == ProductSortingEnum.Initial)
            {
                orderBy = origin.EqualsNoCase("Search/Search") ? _searchSettings.DefaultSortOrder : _catalogSettings.DefaultSortOrder;
            }

            query.CustomData["CurrentSortOrder"] = orderBy.Value;

            query.SortBy(orderBy.Value);
        }
        public async Task <IActionResult> ProductList(GridCommand command, ProductListModel model)
        {
            var gridModel = new GridModel <ProductOverviewModel>();

            var fields = new List <string> {
                "name"
            };

            if (_searchSettings.SearchFields.Contains("sku"))
            {
                fields.Add("sku");
            }

            if (_searchSettings.SearchFields.Contains("shortdescription"))
            {
                fields.Add("shortdescription");
            }

            var searchQuery = new CatalogSearchQuery(fields.ToArray(), model.SearchProductName)
                              .HasStoreId(model.SearchStoreId)
                              .WithCurrency(_workContext.WorkingCurrency)
                              .WithLanguage(_workContext.WorkingLanguage);

            if (model.SearchIsPublished.HasValue)
            {
                searchQuery = searchQuery.PublishedOnly(model.SearchIsPublished.Value);
            }

            if (model.SearchHomePageProducts.HasValue)
            {
                searchQuery = searchQuery.HomePageProductsOnly(model.SearchHomePageProducts.Value);
            }

            if (model.SearchProductTypeId > 0)
            {
                searchQuery = searchQuery.IsProductType((ProductType)model.SearchProductTypeId);
            }

            if (model.SearchWithoutManufacturers.HasValue)
            {
                searchQuery = searchQuery.HasAnyManufacturer(!model.SearchWithoutManufacturers.Value);
            }
            else if (model.SearchManufacturerId != 0)
            {
                searchQuery = searchQuery.WithManufacturerIds(null, model.SearchManufacturerId);
            }


            if (model.SearchWithoutCategories.HasValue)
            {
                searchQuery = searchQuery.HasAnyCategory(!model.SearchWithoutCategories.Value);
            }
            else if (model.SearchCategoryId != 0)
            {
                searchQuery = searchQuery.WithCategoryIds(null, model.SearchCategoryId);
            }

            IPagedList <Product> products;

            if (_searchSettings.UseCatalogSearchInBackend)
            {
                searchQuery = searchQuery.Slice((command.Page - 1) * command.PageSize, command.PageSize);

                var sort = command.Sorting?.FirstOrDefault();
                if (sort != null)
                {
                    switch (sort.Member)
                    {
                    case nameof(ProductModel.Name):
                        searchQuery = searchQuery.SortBy(sort.Descending ? ProductSortingEnum.NameDesc : ProductSortingEnum.NameAsc);
                        break;

                    case nameof(ProductModel.Price):
                        searchQuery = searchQuery.SortBy(sort.Descending ? ProductSortingEnum.PriceDesc : ProductSortingEnum.PriceAsc);
                        break;

                    case nameof(ProductModel.CreatedOn):
                        searchQuery = searchQuery.SortBy(sort.Descending ? ProductSortingEnum.CreatedOn : ProductSortingEnum.CreatedOnAsc);
                        break;
                    }
                }

                if (!searchQuery.Sorting.Any())
                {
                    searchQuery = searchQuery.SortBy(ProductSortingEnum.NameAsc);
                }

                var searchResult = await _catalogSearchService.SearchAsync(searchQuery);

                products = await searchResult.GetHitsAsync();
            }
            else
            {
                var query = _catalogSearchService
                            .PrepareQuery(searchQuery)
                            .ApplyGridCommand(command, false);

                products = await new PagedList <Product>(query, command.Page - 1, command.PageSize).LoadAsync();
            }

            var fileIds = products.AsEnumerable()
                          .Select(x => x.MainPictureId ?? 0)
                          .Where(x => x != 0)
                          .Distinct()
                          .ToArray();

            var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

            gridModel.Rows = products.AsEnumerable().Select(x =>
            {
                var productModel = new ProductOverviewModel
                {
                    Sku                  = x.Sku,
                    Published            = x.Published,
                    ProductTypeLabelHint = x.ProductTypeLabelHint,
                    Name                 = x.Name,
                    Id                        = x.Id,
                    StockQuantity             = x.StockQuantity,
                    Price                     = x.Price,
                    LimitedToStores           = x.LimitedToStores,
                    EditUrl                   = Url.Action("Edit", "Product", new { id = x.Id }),
                    ManufacturerPartNumber    = x.ManufacturerPartNumber,
                    Gtin                      = x.Gtin,
                    MinStockQuantity          = x.MinStockQuantity,
                    OldPrice                  = x.OldPrice,
                    AvailableStartDateTimeUtc = x.AvailableStartDateTimeUtc,
                    AvailableEndDateTimeUtc   = x.AvailableEndDateTimeUtc
                };

                //MiniMapper.Map(x, productModel);

                files.TryGetValue(x.MainPictureId ?? 0, out var file);

                // TODO: (core) Use IImageModel
                productModel.PictureThumbnailUrl = _mediaService.GetUrl(file, _mediaSettings.CartThumbPictureSize);
                productModel.NoThumb             = file == null;

                productModel.ProductTypeName = x.GetProductTypeLabel(_localizationService);
                productModel.UpdatedOn       = _dateTimeHelper.ConvertToUserTime(x.UpdatedOnUtc, DateTimeKind.Utc);
                productModel.CreatedOn       = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);

                return(productModel);
            });

            gridModel.Total = products.TotalCount;

            return(Json(gridModel));
        }
示例#5
0
        public ActionResult Picker(EntityPickerModel model, FormCollection form)
        {
            try
            {
                var languageId = model.LanguageId == 0 ? Services.WorkContext.WorkingLanguage.Id : model.LanguageId;
                var disableIf  = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
                var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList();
                var selected   = model.Selected.SplitSafe(",");
                var returnSku  = model.ReturnField.IsCaseInsensitiveEqual("sku");

                using (var scope = new DbContextScope(Services.DbContext, autoDetectChanges: false, proxyCreation: true, validateOnSave: false, forceNoTracking: true))
                {
                    if (model.EntityType.IsCaseInsensitiveEqual("product"))
                    {
                        model.SearchTerm = model.SearchTerm.TrimSafe();

                        var hasPermission             = Services.Permissions.Authorize(Permissions.Catalog.Product.Read);
                        var disableIfNotSimpleProduct = disableIf.Contains("notsimpleproduct");
                        var disableIfGroupedProduct   = disableIf.Contains("groupedproduct");
                        var labelTextGrouped          = T("Admin.Catalog.Products.ProductType.GroupedProduct.Label").Text;
                        var labelTextBundled          = T("Admin.Catalog.Products.ProductType.BundledProduct.Label").Text;
                        var sku = T("Products.Sku").Text;

                        var fields = new List <string> {
                            "name"
                        };
                        if (_searchSettings.SearchFields.Contains("sku"))
                        {
                            fields.Add("sku");
                        }
                        if (_searchSettings.SearchFields.Contains("shortdescription"))
                        {
                            fields.Add("shortdescription");
                        }

                        var searchQuery = new CatalogSearchQuery(fields.ToArray(), model.SearchTerm)
                                          .HasStoreId(model.StoreId);

                        if (!hasPermission)
                        {
                            searchQuery = searchQuery.VisibleOnly(Services.WorkContext.CurrentCustomer);
                        }

                        if (model.ProductTypeId > 0)
                        {
                            searchQuery = searchQuery.IsProductType((ProductType)model.ProductTypeId);
                        }

                        if (model.ManufacturerId != 0)
                        {
                            searchQuery = searchQuery.WithManufacturerIds(null, model.ManufacturerId);
                        }

                        if (model.CategoryId != 0)
                        {
                            var node = _categoryService.GetCategoryTree(model.CategoryId, true);
                            if (node != null)
                            {
                                searchQuery = searchQuery.WithCategoryIds(null, node.Flatten(true).Select(x => x.Id).ToArray());
                            }
                        }

                        List <EntityPickerProduct> products;
                        var skip = model.PageIndex * model.PageSize;

                        if (_searchSettings.UseCatalogSearchInBackend)
                        {
                            searchQuery = searchQuery
                                          .Slice(skip, model.PageSize)
                                          .SortBy(ProductSortingEnum.NameAsc);

                            var searchResult = _catalogSearchService.Search(searchQuery);
                            products = searchResult.Hits
                                       .Select(x => new EntityPickerProduct
                            {
                                Id            = x.Id,
                                Sku           = x.Sku,
                                Name          = x.Name,
                                Published     = x.Published,
                                ProductTypeId = x.ProductTypeId,
                                MainPictureId = x.MainPictureId
                            })
                                       .ToList();
                        }
                        else
                        {
                            var query = _catalogSearchService.PrepareQuery(searchQuery);

                            products = query
                                       .Select(x => new EntityPickerProduct
                            {
                                Id            = x.Id,
                                Sku           = x.Sku,
                                Name          = x.Name,
                                Published     = x.Published,
                                ProductTypeId = x.ProductTypeId,
                                MainPictureId = x.MainPictureId
                            })
                                       .OrderBy(x => x.Name)
                                       .Skip(() => skip)
                                       .Take(() => model.PageSize)
                                       .ToList();
                        }

                        var fileIds = products
                                      .Select(x => x.MainPictureId ?? 0)
                                      .Where(x => x != 0)
                                      .Distinct()
                                      .ToArray();

                        var files = _mediaService.GetFilesByIds(fileIds).ToDictionarySafe(x => x.Id);

                        model.SearchResult = products
                                             .Select(x =>
                        {
                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id           = x.Id,
                                Title        = x.Name,
                                Summary      = x.Sku,
                                SummaryTitle = "{0}: {1}".FormatInvariant(sku, x.Sku.NaIfEmpty()),
                                Published    = hasPermission ? x.Published : (bool?)null,
                                ReturnValue  = returnSku ? x.Sku : x.Id.ToString()
                            };

                            item.Selected = selected.Contains(item.ReturnValue);

                            if (disableIfNotSimpleProduct)
                            {
                                item.Disable = x.ProductTypeId != (int)ProductType.SimpleProduct;
                            }
                            else if (disableIfGroupedProduct)
                            {
                                item.Disable = x.ProductTypeId == (int)ProductType.GroupedProduct;
                            }

                            if (!item.Disable && disableIds.Contains(x.Id))
                            {
                                item.Disable = true;
                            }

                            if (x.ProductTypeId == (int)ProductType.GroupedProduct)
                            {
                                item.LabelText      = labelTextGrouped;
                                item.LabelClassName = "badge-success";
                            }
                            else if (x.ProductTypeId == (int)ProductType.BundledProduct)
                            {
                                item.LabelText      = labelTextBundled;
                                item.LabelClassName = "badge-info";
                            }

                            files.TryGetValue(x.MainPictureId ?? 0, out var file);
                            item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                            return(item);
                        })
                                             .ToList();
                    }
                    else if (model.EntityType.IsCaseInsensitiveEqual("category"))
                    {
                        var categories = _categoryService.GetAllCategories(model.SearchTerm, showHidden: true);

                        var fileIds = categories
                                      .Select(x => x.MediaFileId ?? 0)
                                      .Where(x => x != 0)
                                      .Distinct()
                                      .ToArray();

                        var files = _mediaService.GetFilesByIds(fileIds).ToDictionarySafe(x => x.Id);

                        model.SearchResult = categories
                                             .Select(x =>
                        {
                            var path = ((ICategoryNode)x).GetCategoryPath(_categoryService, languageId, "({0})");
                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id           = x.Id,
                                Title        = x.Name,
                                Summary      = path,
                                SummaryTitle = path,
                                Published    = x.Published,
                                ReturnValue  = x.Id.ToString(),
                                Selected     = selected.Contains(x.Id.ToString()),
                                Disable      = disableIds.Contains(x.Id)
                            };

                            if (x.Alias.HasValue())
                            {
                                item.LabelText      = x.Alias;
                                item.LabelClassName = "badge-secondary";
                            }

                            files.TryGetValue(x.MediaFileId ?? 0, out var file);
                            item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                            return(item);
                        })
                                             .ToList();
                    }
                    else if (model.EntityType.IsCaseInsensitiveEqual("manufacturer"))
                    {
                        var manufacturers = _manufacturerService.GetAllManufacturers(model.SearchTerm, model.PageIndex, model.PageSize, showHidden: true);

                        var fileIds = manufacturers
                                      .Select(x => x.MediaFileId ?? 0)
                                      .Where(x => x != 0)
                                      .Distinct()
                                      .ToArray();

                        var files = _mediaService.GetFilesByIds(fileIds).ToDictionarySafe(x => x.Id);

                        model.SearchResult = manufacturers
                                             .Select(x =>
                        {
                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id          = x.Id,
                                Title       = x.Name,
                                Published   = x.Published,
                                ReturnValue = x.Id.ToString(),
                                Selected    = selected.Contains(x.Id.ToString()),
                                Disable     = disableIds.Contains(x.Id)
                            };

                            files.TryGetValue(x.MediaFileId ?? 0, out var file);
                            item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                            return(item);
                        })
                                             .ToList();
                    }
                    else if (model.EntityType.IsCaseInsensitiveEqual("customer"))
                    {
                        var registeredRoleId         = _customerService.GetCustomerRoleBySystemName("Registered").Id;
                        var searchTermName           = string.Empty;
                        var searchTermEmail          = string.Empty;
                        var searchTermCustomerNumber = string.Empty;

                        if (model.CustomerSearchType.IsCaseInsensitiveEqual("Name"))
                        {
                            searchTermName = model.SearchTerm;
                        }
                        else if (model.CustomerSearchType.IsCaseInsensitiveEqual("Email"))
                        {
                            searchTermEmail = model.SearchTerm;
                        }
                        else if (model.CustomerSearchType.IsCaseInsensitiveEqual("CustomerNumber"))
                        {
                            searchTermCustomerNumber = model.SearchTerm;
                        }

                        var q = new CustomerSearchQuery
                        {
                            SearchTerm      = searchTermName,
                            Email           = searchTermEmail,
                            CustomerNumber  = searchTermCustomerNumber,
                            CustomerRoleIds = new int[] { registeredRoleId },
                            PageIndex       = model.PageIndex,
                            PageSize        = model.PageSize
                        };

                        var customers = _customerService.SearchCustomers(q);

                        model.SearchResult = customers
                                             .Select(x =>
                        {
                            var fullName = x.GetFullName();

                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id           = x.Id,
                                ReturnValue  = x.Id.ToString(),
                                Title        = x.Username.NullEmpty() ?? x.Email,
                                Summary      = fullName,
                                SummaryTitle = fullName,
                                Published    = true,
                                Selected     = selected.Contains(x.Id.ToString()),
                                Disable      = disableIds.Contains(x.Id)
                            };

                            return(item);
                        })
                                             .ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                NotifyError(ex.ToAllMessages());
            }

            return(PartialView("Picker.List", model));
        }
示例#6
0
        public async Task <IActionResult> PickerPost(EntityPickerModel model)
        {
            try
            {
                var form       = Request.Form;
                var disableIf  = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
                var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList();
                var selected   = model.Selected.SplitSafe(",");
                var returnSku  = model.ReturnField.EqualsNoCase("sku");

                using var scope = new DbContextScope(Services.DbContext, autoDetectChanges: false, forceNoTracking: true);
                if (model.EntityType.EqualsNoCase("product"))
                {
                    model.SearchTerm = model.SearchTerm.TrimSafe();

                    var hasPermission = await Services.Permissions.AuthorizeAsync(Permissions.Catalog.Product.Read);

                    var disableIfNotSimpleProduct = disableIf.Contains("notsimpleproduct");
                    var disableIfGroupedProduct   = disableIf.Contains("groupedproduct");
                    var labelTextGrouped          = T("Admin.Catalog.Products.ProductType.GroupedProduct.Label").Value;
                    var labelTextBundled          = T("Admin.Catalog.Products.ProductType.BundledProduct.Label").Value;
                    var sku = T("Products.Sku");

                    var fields = new List <string> {
                        "name"
                    };
                    if (_searchSettings.SearchFields.Contains("sku"))
                    {
                        fields.Add("sku");
                    }
                    if (_searchSettings.SearchFields.Contains("shortdescription"))
                    {
                        fields.Add("shortdescription");
                    }

                    var searchQuery = new CatalogSearchQuery(fields.ToArray(), model.SearchTerm)
                                      .HasStoreId(model.StoreId);

                    if (!hasPermission)
                    {
                        searchQuery = searchQuery.VisibleOnly(Services.WorkContext.CurrentCustomer);
                    }

                    if (model.ProductTypeId > 0)
                    {
                        searchQuery = searchQuery.IsProductType((ProductType)model.ProductTypeId);
                    }

                    if (model.ManufacturerId != 0)
                    {
                        searchQuery = searchQuery.WithManufacturerIds(null, model.ManufacturerId);
                    }

                    if (model.CategoryId != 0)
                    {
                        var node = await _categoryService.GetCategoryTreeAsync(model.CategoryId, true);

                        if (node != null)
                        {
                            searchQuery = searchQuery.WithCategoryIds(null, node.Flatten(true).Select(x => x.Id).ToArray());
                        }
                    }

                    List <EntityPickerProduct> products;
                    var skip = model.PageIndex * model.PageSize;

                    if (_searchSettings.UseCatalogSearchInBackend)
                    {
                        searchQuery = searchQuery
                                      .Slice(skip, model.PageSize)
                                      .SortBy(ProductSortingEnum.NameAsc);

                        var searchResult = await _catalogSearchService.SearchAsync(searchQuery);

                        products = (await searchResult.GetHitsAsync())
                                   .Select(x => new EntityPickerProduct
                        {
                            Id            = x.Id,
                            Sku           = x.Sku,
                            Name          = x.Name,
                            Published     = x.Published,
                            ProductTypeId = x.ProductTypeId,
                            MainPictureId = x.MainPictureId
                        })
                                   .ToList();
                    }
                    else
                    {
                        var query = _catalogSearchService.PrepareQuery(searchQuery).AsNoTracking();

                        products = await query
                                   .Select(x => new EntityPickerProduct
                        {
                            Id            = x.Id,
                            Sku           = x.Sku,
                            Name          = x.Name,
                            Published     = x.Published,
                            ProductTypeId = x.ProductTypeId,
                            MainPictureId = x.MainPictureId
                        })
                                   .OrderBy(x => x.Name)
                                   .Skip(skip)
                                   .Take(model.PageSize)
                                   .ToListAsync();
                    }

                    var fileIds = products
                                  .Select(x => x.MainPictureId ?? 0)
                                  .Where(x => x != 0)
                                  .Distinct()
                                  .ToArray();

                    var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

                    model.SearchResult = products
                                         .Select(x =>
                    {
                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id           = x.Id,
                            Title        = x.Name,
                            Summary      = x.Sku,
                            SummaryTitle = $"{sku}: {x.Sku.NaIfEmpty()}",
                            Published    = hasPermission ? x.Published : null,
                            ReturnValue  = returnSku ? x.Sku : x.Id.ToString()
                        };

                        item.Selected = selected.Contains(item.ReturnValue);

                        if (disableIfNotSimpleProduct)
                        {
                            item.Disable = x.ProductTypeId != (int)ProductType.SimpleProduct;
                        }
                        else if (disableIfGroupedProduct)
                        {
                            item.Disable = x.ProductTypeId == (int)ProductType.GroupedProduct;
                        }

                        if (!item.Disable && disableIds.Contains(x.Id))
                        {
                            item.Disable = true;
                        }

                        if (x.ProductTypeId == (int)ProductType.GroupedProduct)
                        {
                            item.LabelText      = labelTextGrouped;
                            item.LabelClassName = "badge-success";
                        }
                        else if (x.ProductTypeId == (int)ProductType.BundledProduct)
                        {
                            item.LabelText      = labelTextBundled;
                            item.LabelClassName = "badge-info";
                        }

                        files.TryGetValue(x.MainPictureId ?? 0, out var file);
                        item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                        return(item);
                    })
                                         .ToList();
                }
                else if (model.EntityType.EqualsNoCase("category"))
                {
                    var categoryQuery = _db.Categories
                                        .AsNoTracking()
                                        .ApplyStandardFilter(includeHidden: true)
                                        .AsQueryable();

                    if (model.SearchTerm.HasValue())
                    {
                        categoryQuery = categoryQuery.Where(c => c.Name.Contains(model.SearchTerm) || c.FullName.Contains(model.SearchTerm));
                    }

                    var categories = await categoryQuery.ToListAsync();

                    var fileIds = categories
                                  .Select(x => x.MediaFileId ?? 0)
                                  .Where(x => x != 0)
                                  .Distinct()
                                  .ToArray();

                    var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

                    model.SearchResult = await categories
                                         .SelectAsync(async x =>
                    {
                        var path = await _categoryService.GetCategoryPathAsync(x, Services.WorkContext.WorkingLanguage.Id, "({0})");
                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id           = x.Id,
                            Title        = x.Name,
                            Summary      = path,
                            SummaryTitle = path,
                            Published    = x.Published,
                            ReturnValue  = x.Id.ToString(),
                            Selected     = selected.Contains(x.Id.ToString()),
                            Disable      = disableIds.Contains(x.Id)
                        };

                        if (x.Alias.HasValue())
                        {
                            item.LabelText      = x.Alias;
                            item.LabelClassName = "badge-secondary";
                        }

                        files.TryGetValue(x.MediaFileId ?? 0, out var file);
                        item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                        return(item);
                    }).AsyncToList();
                }
                else if (model.EntityType.EqualsNoCase("manufacturer"))
                {
                    var manufacturerQuery = _db.Manufacturers
                                            .AsNoTracking()
                                            .ApplyStandardFilter(includeHidden: true)
                                            .AsQueryable();

                    if (model.SearchTerm.HasValue())
                    {
                        manufacturerQuery = manufacturerQuery.Where(c => c.Name.Contains(model.SearchTerm));
                    }

                    var manufacturers = await manufacturerQuery
                                        .ApplyPaging(model.PageIndex, model.PageSize)
                                        .ToListAsync();

                    var fileIds = manufacturers
                                  .Select(x => x.MediaFileId ?? 0)
                                  .Where(x => x != 0)
                                  .Distinct()
                                  .ToArray();

                    var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

                    model.SearchResult = manufacturers
                                         .Select(x =>
                    {
                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id          = x.Id,
                            Title       = x.Name,
                            Published   = x.Published,
                            ReturnValue = x.Id.ToString(),
                            Selected    = selected.Contains(x.Id.ToString()),
                            Disable     = disableIds.Contains(x.Id)
                        };

                        files.TryGetValue(x.MediaFileId ?? 0, out var file);
                        item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                        return(item);
                    })
                                         .ToList();
                }
                else if (model.EntityType.EqualsNoCase("customer"))
                {
                    var registeredRole = await _db.CustomerRoles
                                         .AsNoTracking()
                                         .FirstOrDefaultAsync(x => x.SystemName == SystemCustomerRoleNames.Registered);

                    var registeredRoleId = registeredRole.Id;

                    var customerQuery = _db.Customers
                                        .AsNoTracking()
                                        .AsQueryable();

                    if (model.SearchTerm.HasValue())
                    {
                        if (model.CustomerSearchType.EqualsNoCase("Name"))
                        {
                            customerQuery = customerQuery.ApplySearchTermFilter(model.SearchTerm);
                        }
                        else if (model.CustomerSearchType.EqualsNoCase("Email"))
                        {
                            customerQuery = customerQuery.ApplyIdentFilter(email: model.SearchTerm, userName: model.SearchTerm);
                        }
                        else if (model.CustomerSearchType.EqualsNoCase("CustomerNumber"))
                        {
                            customerQuery = customerQuery.ApplyIdentFilter(customerNumber: model.SearchTerm);
                        }
                    }

                    var customers = await customerQuery
                                    .ApplyRolesFilter(new[] { registeredRoleId })
                                    .ApplyPaging(model.PageIndex, model.PageSize)
                                    .ToListAsync();

                    model.SearchResult = customers
                                         .Select(x =>
                    {
                        var fullName = x.GetFullName();

                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id           = x.Id,
                            ReturnValue  = x.Id.ToString(),
                            Title        = x.Username.NullEmpty() ?? x.Email,
                            Summary      = fullName,
                            SummaryTitle = fullName,
                            Published    = true,
                            Selected     = selected.Contains(x.Id.ToString()),
                            Disable      = disableIds.Contains(x.Id)
                        };

                        return(item);
                    })
                                         .ToList();
                }
            }
            catch (Exception ex)
            {
                NotifyError(ex.ToAllMessages());
            }

            return(PartialView("Picker.List", model));
        }