I want to override the method GetAllCategoriesByParentCategoryId to sort by Category Name by creating a class in my themes folder.
The code below doesn't work because it creates a namespace in nop.web and not nop.services
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nop.Services.Catalog;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Data;
using Nop.Core.Domain.Catalog;
using Nop.Core.Events;
namespace Nop.Services.Catalog
{
public class CategoryServiceCustom : CategoryService
{
private readonly IRepository<Category> _categoryRepository;
private readonly IRepository<ProductCategory> _productCategoryRepository;
private readonly IRepository<Product> _productRepository;
private readonly IEventPublisher _eventPublisher;
private readonly ICacheManager _cacheManager;
/// <summary>
/// Ctor
/// </summary>
/// <param name="cacheManager">Cache manager</param>
/// <param name="categoryRepository">Category repository</param>
/// <param name="productCategoryRepository">ProductCategory repository</param>
/// <param name="productRepository">Product repository</param>
/// <param name="eventPublisher">Event publisher</param>
public CategoryServiceCustom(ICacheManager cacheManager,
IRepository<Category> categoryRepository,
IRepository<ProductCategory> productCategoryRepository,
IRepository<Product> productRepository,
IEventPublisher eventPublisher)
: base(cacheManager,
categoryRepository,
productCategoryRepository,
productRepository,
eventPublisher)
{
this._cacheManager = cacheManager;
this._categoryRepository = categoryRepository;
this._productCategoryRepository = productCategoryRepository;
this._productRepository = productRepository;
_eventPublisher = eventPublisher;
}
new public IList<Category> GetAllCategoriesByParentCategoryId(int parentCategoryId,
bool showHidden = false)
{
var query = from c in _categoryRepository.Table
orderby c.Name
where (showHidden || c.Published) &&
!c.Deleted &&
c.ParentCategoryId == parentCategoryId
select c;
//filter by access control list (public store)
//if (!showHidden)
//{
// query = query.WhereAclPerObjectNotDenied(_categoryRepository);
//}
var categories = query.ToList();
return categories;
}
}
}