public async Task CanPrepareCategoryModel()
        {
            var model = await _catalogModelFactory.PrepareCategoryModelAsync(_category, new CatalogPagingFilteringModel());

            model.Id.Should().Be(_category.Id);
            model.Name.Should().Be(_category.Name);
            model.Description.Should().Be(_category.Description);
            model.MetaKeywords.Should().Be(_category.MetaKeywords);
            model.MetaDescription.Should().Be(_category.MetaDescription);
            model.MetaTitle.Should().Be(_category.MetaTitle);

            model.CategoryBreadcrumb.Any().Should().BeTrue();
            model.CategoryBreadcrumb.FirstOrDefault()?.Name.Should().Be("Computers");
            model.SubCategories.Count.Should().Be(3);
        }
Esempio n. 2
0
        public virtual async Task <IActionResult> Category(int categoryId, CatalogProductsCommand command)
        {
            var category = await _categoryService.GetCategoryByIdAsync(categoryId);

            if (!await CheckCategoryAvailabilityAsync(category))
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            await _genericAttributeService.SaveAttributeAsync(await _workContext.GetCurrentCustomerAsync(),
                                                              NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                              _webHelper.GetThisPageUrl(false),
                                                              (await _storeContext.GetCurrentStoreAsync()).Id);

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

            //activity log
            await _customerActivityService.InsertActivityAsync("PublicStore.ViewCategory",
                                                               string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.ViewCategory"), category.Name), category);

            //model
            var model = await _catalogModelFactory.PrepareCategoryModelAsync(category, command);

            //template
            var templateViewPath = await _catalogModelFactory.PrepareCategoryTemplateViewPathAsync(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }
Esempio n. 3
0
        public async Task PrepareCategoryModelShouldDependOnSettings()
        {
            var model = await _catalogModelFactory.PrepareCategoryModelAsync(_category, new CatalogProductsCommand());

            model.CategoryBreadcrumb.Any().Should().BeFalse();
            model.SubCategories.Count.Should().Be(3);
            model.CatalogProductsModel.Products.Count.Should().Be(6);
        }
Esempio n. 4
0
        public virtual async Task <IActionResult> Category(int categoryId, CatalogPagingFilteringModel command)
        {
            var category = await _categoryService.GetCategoryByIdAsync(categoryId);

            if (category == null || category.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !category.Published ||
                //ACL (access control list)
                !await _aclService.AuthorizeAsync(category) ||
                //Store mapping
                !await _storeMappingService.AuthorizeAsync(category);

            //Check whether the current user has a "Manage categories" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            var hasAdminAccess = await _permissionService.AuthorizeAsync(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories);

            if (notAvailable && !hasAdminAccess)
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            await _genericAttributeService.SaveAttributeAsync(await _workContext.GetCurrentCustomerAsync(),
                                                              NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                              _webHelper.GetThisPageUrl(false),
                                                              (await _storeContext.GetCurrentStoreAsync()).Id);

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

            //activity log
            await _customerActivityService.InsertActivityAsync("PublicStore.ViewCategory",
                                                               string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.ViewCategory"), category.Name), category);

            //model
            var model = await _catalogModelFactory.PrepareCategoryModelAsync(category, command);

            //template
            var templateViewPath = await _catalogModelFactory.PrepareCategoryTemplateViewPathAsync(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }