public async Task CanPrepareManufacturerTemplateViewPath()
        {
            var model = await _catalogModelFactory.PrepareManufacturerTemplateViewPathAsync(1);

            model.Should().Be("ManufacturerTemplate.ProductsInGridOrLines");

            model = await _catalogModelFactory.PrepareManufacturerTemplateViewPathAsync(int.MaxValue);

            model.Should().Be("ManufacturerTemplate.ProductsInGridOrLines");
        }
Esempio n. 2
0
        public virtual async Task <IActionResult> Manufacturer(int manufacturerId, CatalogProductsCommand command)
        {
            var manufacturer = await _manufacturerService.GetManufacturerByIdAsync(manufacturerId);

            if (!await CheckManufacturerAvailabilityAsync(manufacturer))
            {
                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.ManageManufacturers))
            {
                DisplayEditLink(Url.Action("Edit", "Manufacturer", new { id = manufacturer.Id, area = AreaNames.Admin }));
            }

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

            //model
            var model = await _catalogModelFactory.PrepareManufacturerModelAsync(manufacturer, command);

            //template
            var templateViewPath = await _catalogModelFactory.PrepareManufacturerTemplateViewPathAsync(manufacturer.ManufacturerTemplateId);

            return(View(templateViewPath, model));
        }
Esempio n. 3
0
        public virtual async Task <IActionResult> Manufacturer(int manufacturerId, CatalogPagingFilteringModel command)
        {
            var manufacturer = await _manufacturerService.GetManufacturerByIdAsync(manufacturerId);

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

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

            //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.ManageManufacturers);

            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.ManageManufacturers))
            {
                DisplayEditLink(Url.Action("Edit", "Manufacturer", new { id = manufacturer.Id, area = AreaNames.Admin }));
            }

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

            //model
            var model = await _catalogModelFactory.PrepareManufacturerModelAsync(manufacturer, command);

            //template
            var templateViewPath = await _catalogModelFactory.PrepareManufacturerTemplateViewPathAsync(manufacturer.ManufacturerTemplateId);

            return(View(templateViewPath, model));
        }