nopCommerce 4.1: Bug in CategoryService Method GetCategoryBreadCrumb

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Line number 760 looks like this:
  

category = allCategories != null ? allCategories.FirstOrDefault(c => c.Id == c.ParentCategoryId)
  

it must be like this:

category = allCategories != null ? allCategories.FirstOrDefault(c => c.Id == category.ParentCategoryId)


here is the current full code:

public virtual IList<Category> GetCategoryBreadCrumb(Category category, IList<Category> allCategories = null, bool showHidden = false)
        {
            if (category == null)
                throw new ArgumentNullException(nameof(category));

            var result = new List<Category>();

            //used to prevent circular references
            var alreadyProcessedCategoryIds = new List<int>();

            while (category != null && //not null
                !category.Deleted && //not deleted
                (showHidden || category.Published) && //published
                (showHidden || _aclService.Authorize(category)) && //ACL
                (showHidden || _storeMappingService.Authorize(category)) && //Store mapping
                !alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references
            {
                result.Add(category);

                alreadyProcessedCategoryIds.Add(category.Id);

                category = allCategories != null ? allCategories.FirstOrDefault(c => c.Id == category.ParentCategoryId)
                    : this.GetCategoryById(category.ParentCategoryId);
            }
            result.Reverse();
            return result;
        }
5 years ago
currently the method doesn't work properly when allCategories List is provided.
5 years ago
Thanks a lot! Fixed
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.