vc-module-catalog icon indicating copy to clipboard operation
vc-module-catalog copied to clipboard

Could not find Category by code if category is empty

Open OlegoO opened this issue 6 years ago • 1 comments

We could not find category id by code if category is empty

Expected behavior

Find category by code if category is empty

Actual behavior

Categories is empty. I see result if I add any product into category.

Steps to reproduce

 private readonly ICatalogSearchService _searchService;

            var searchCreteria = new SearchCriteria
            {
                ResponseGroup = SearchResponseGroup.WithCategories,
                Code = categoryCode,
                CatalogId = catalogId,
                Take = 1,
                Skip = 0,
                SearchInChildren = true
            };
            var result = _searchService.Search(searchCreteria);
            result.Categories.FirstOrDefault();

OlegoO avatar Mar 20 '18 15:03 OlegoO

I used workaround

private readonly Func<ICatalogRepository> _catalogRepositoryFactory;

using (var catalogRepository = _catalogRepositoryFactory())
            {
                return catalogRepository.Categories.Where(c => c.CatalogId == catalogId && c.Code == categoryCode).Select(c => c.Id).FirstOrDefault();
            }

OlegoO avatar Mar 21 '18 10:03 OlegoO