Thank You for an advice. Here is the code:
[AutoValidateAntiforgeryToken]
public partial class ArcaneProductController : ProductController
{
#region Fields
private readonly CaptchaSettings _captchaSettings;
private readonly CatalogSettings _catalogSettings;
private readonly IAclService _aclService;
private readonly ICompareProductsService _compareProductsService;
private readonly ICustomerActivityService _customerActivityService;
private readonly ICustomerService _customerService;
private readonly IEventPublisher _eventPublisher;
private readonly ILocalizationService _localizationService;
private readonly IOrderService _orderService;
private readonly IPermissionService _permissionService;
private readonly IProductAttributeParser _productAttributeParser;
private readonly ArcaneProductModelFactory _productModelFactory;
private readonly IProductService _productService;
private readonly IRecentlyViewedProductsService _recentlyViewedProductsService;
private readonly IReviewTypeService _reviewTypeService;
private readonly IShoppingCartModelFactory _shoppingCartModelFactory;
private readonly IShoppingCartService _shoppingCartService;
private readonly IStoreContext _storeContext;
private readonly IStoreMappingService _storeMappingService;
private readonly IUrlRecordService _urlRecordService;
private readonly IWebHelper _webHelper;
private readonly IWorkContext _workContext;
private readonly IWorkflowMessageService _workflowMessageService;
private readonly LocalizationSettings _localizationSettings;
private readonly ShoppingCartSettings _shoppingCartSettings;
#endregion
#region Ctor
public ArcaneProductController(CaptchaSettings captchaSettings,
CatalogSettings catalogSettings,
IAclService aclService,
ICompareProductsService compareProductsService,
ICustomerActivityService customerActivityService,
ICustomerService customerService,
IEventPublisher eventPublisher,
ILocalizationService localizationService,
IOrderService orderService,
IPermissionService permissionService,
IProductAttributeParser productAttributeParser,
ArcaneProductModelFactory productModelFactory,
IProductService productService,
IRecentlyViewedProductsService recentlyViewedProductsService,
IReviewTypeService reviewTypeService,
IShoppingCartModelFactory shoppingCartModelFactory,
IShoppingCartService shoppingCartService,
IStoreContext storeContext,
IStoreMappingService storeMappingService,
IUrlRecordService urlRecordService,
IWebHelper webHelper,
IWorkContext workContext,
IWorkflowMessageService workflowMessageService,
LocalizationSettings localizationSettings,
ShoppingCartSettings shoppingCartSettings) : base
(captchaSettings,
catalogSettings,
aclService,
compareProductsService,
customerActivityService,
customerService,
eventPublisher,
localizationService,
orderService,
permissionService,
productAttributeParser,
productModelFactory,
productService,
recentlyViewedProductsService,
reviewTypeService,
shoppingCartModelFactory,
shoppingCartService,
storeContext,
storeMappingService,
urlRecordService,
webHelper,
workContext,
workflowMessageService,
localizationSettings,
shoppingCartSettings
)
{
_captchaSettings = captchaSettings;
_catalogSettings = catalogSettings;
_aclService = aclService;
_compareProductsService = compareProductsService;
_customerActivityService = customerActivityService;
_customerService = customerService;
_eventPublisher = eventPublisher;
_localizationService = localizationService;
_orderService = orderService;
_permissionService = permissionService;
_productAttributeParser = productAttributeParser;
_productModelFactory = productModelFactory;
_productService = productService;
_reviewTypeService = reviewTypeService;
_recentlyViewedProductsService = recentlyViewedProductsService;
_shoppingCartModelFactory = shoppingCartModelFactory;
_shoppingCartService = shoppingCartService;
_storeContext = storeContext;
_storeMappingService = storeMappingService;
_urlRecordService = urlRecordService;
_webHelper = webHelper;
_workContext = workContext;
_workflowMessageService = workflowMessageService;
_localizationSettings = localizationSettings;
_shoppingCartSettings = shoppingCartSettings;
}
#endregion
#region Methods
override public IActionResult RecentlyViewedProducts()
{
if (!_catalogSettings.RecentlyViewedProductsEnabled)
return Content("");
var products = _recentlyViewedProductsService.GetRecentlyViewedProducts(_catalogSettings.RecentlyViewedProductsNumber);
var model = new List<ProductOverviewModel>();
model.AddRange(_productModelFactory.PrepareArcaneProductOverviewModels(products));
return View(model);
}
override public IActionResult NewProducts()
{
if (!_catalogSettings.NewProductsEnabled)
return Content("");
var products = _productService.SearchProducts(
storeId: _storeContext.CurrentStore.Id,
visibleIndividuallyOnly: true,
markedAsNewOnly: true,
orderBy: ProductSortingEnum.CreatedOn,
pageSize: _catalogSettings.NewProductsNumber);
var model = new List<ProductOverviewModel>();
model.AddRange(_productModelFactory.PrepareArcaneProductOverviewModels(products));
return View(model);
}
public override IActionResult CompareProducts()
{
if (!_catalogSettings.CompareProductsEnabled)
return RedirectToRoute("Homepage");
var model = new CompareProductsModel
{
IncludeShortDescriptionInCompareProducts = _catalogSettings.IncludeShortDescriptionInCompareProducts,
IncludeFullDescriptionInCompareProducts = _catalogSettings.IncludeFullDescriptionInCompareProducts,
};
var products = _compareProductsService.GetComparedProducts();
//ACL and store mapping
products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
//availability dates
products = products.Where(p => _productService.ProductIsAvailable(p)).ToList();
//prepare model
_productModelFactory.PrepareArcaneProductOverviewModels(products, prepareSpecificationAttributes: true)
.ToList()
.ForEach(model.Products.Add);
return View(model);
}
#endregion
}