Exemple #1
0
        public virtual async Task <IActionResult> Category(string categoryId, CatalogPagingFilteringModel command)
        {
            var category = await _catalogViewModelService.GetCategoryById(categoryId);

            if (category == null)
            {
                return(InvokeHttp404());
            }

            var customer = _workContext.CurrentCustomer;

            //Check whether the current user has a "Manage catalog" permission
            //It allows him to preview a category before publishing
            if (!category.Published && !await _permissionService.Authorize(StandardPermissionProvider.ManageCategories, customer))
            {
                return(InvokeHttp404());
            }

            //ACL (access control list)
            if (!_aclService.Authorize(category, customer))
            {
                return(InvokeHttp404());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(category))
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            await SaveLastContinueShoppingPage(customer);

            //display "edit" (manage) link
            if (await _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel, customer) && await _permissionService.Authorize(StandardPermissionProvider.ManageCategories, customer))
            {
                DisplayEditLink(Url.Action("Edit", "Category", new { id = category.Id, area = "Admin" }));
            }

            //activity log
            await _customerActivityService.InsertActivity("PublicStore.ViewCategory", category.Id, _localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name);

            await _customerActionEventService.Viewed(customer, this.HttpContext.Request.Path.ToString(), this.Request.Headers[HeaderNames.Referer].ToString() != null?Request.Headers["Referer"].ToString() : "");

            //model
            var model = await _catalogViewModelService.PrepareCategory(category, command);

            //template
            var templateViewPath = await _catalogViewModelService.PrepareCategoryTemplateViewPath(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }