Ejemplo n.º 1
0
        public async Task <IActionResult> ManufacturerTemplates(DataSourceRequest command)
        {
            var templatesModel = (await _manufacturerTemplateService.GetAllManufacturerTemplates())
                                 .Select(x => x.ToModel())
                                 .ToList();
            var gridModel = new DataSourceResult
            {
                Data  = templatesModel,
                Total = templatesModel.Count
            };

            return(Json(gridModel));
        }
        /// <summary>
        /// Prepare paged manufacturer template list model
        /// </summary>
        /// <param name="searchModel">Manufacturer template search model</param>
        /// <returns>Manufacturer template list model</returns>
        public virtual ManufacturerTemplateListModel PrepareManufacturerTemplateListModel(ManufacturerTemplateSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get manufacturer templates
            var manufacturerTemplates = _manufacturerTemplateService.GetAllManufacturerTemplates().ToPagedList(searchModel);

            //prepare grid model
            var model = new ManufacturerTemplateListModel().PrepareToGrid(searchModel, manufacturerTemplates,
                                                                          () => manufacturerTemplates.Select(template => template.ToModel <ManufacturerTemplateModel>()));

            return(model);
        }
Ejemplo n.º 3
0
        public virtual async Task PrepareTemplatesModel(ManufacturerModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var templates = await _manufacturerTemplateService.GetAllManufacturerTemplates();

            foreach (var template in templates)
            {
                model.AvailableManufacturerTemplates.Add(new SelectListItem
                {
                    Text  = template.Name,
                    Value = template.Id.ToString()
                });
            }
        }
Ejemplo n.º 4
0
        public virtual ActionResult ManufacturerTemplates(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedKendoGridJson());
            }

            var templatesModel = _manufacturerTemplateService.GetAllManufacturerTemplates()
                                 .Select(x => x.ToModel())
                                 .ToList();
            var gridModel = new DataSourceResult
            {
                Data  = templatesModel,
                Total = templatesModel.Count
            };

            return(Json(gridModel));
        }
Ejemplo n.º 5
0
        protected virtual void PrepareTemplatesModel(ManufacturerModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var templates = _manufacturerTemplateService.GetAllManufacturerTemplates();

            foreach (var template in templates)
            {
                model.AvailableManufacturerTemplates.Add(new SelectListItem
                {
                    Text  = template.Name,
                    Value = template.Id.ToString()
                });
            }
        }
        public async Task <string> Handle(GetManufacturerTemplateViewPath request, CancellationToken cancellationToken)
        {
            var templateCacheKey = string.Format(ModelCacheEventConst.MANUFACTURER_TEMPLATE_MODEL_KEY, request.TemplateId);
            var templateViewPath = await _cacheManager.GetAsync(templateCacheKey, async() =>
            {
                var template = await _manufacturerTemplateService.GetManufacturerTemplateById(request.TemplateId);
                if (template == null)
                {
                    template = (await _manufacturerTemplateService.GetAllManufacturerTemplates()).FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            return(templateViewPath);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Prepare manufacturer template view path
        /// </summary>
        /// <param name="templateId">Template identifier</param>
        /// <returns>Manufacturer template view path</returns>
        public virtual string PrepareManufacturerTemplateViewPath(int templateId)
        {
            var templateCacheKey = string.Format(ModelCacheEventConsumer.MANUFACTURER_TEMPLATE_MODEL_KEY, templateId);
            var templateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _manufacturerTemplateService.GetManufacturerTemplateById(templateId);
                if (template == null)
                {
                    template = _manufacturerTemplateService.GetAllManufacturerTemplates().FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            return(templateViewPath);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Prepare paged manufacturer template list model
        /// </summary>
        /// <param name="searchModel">Manufacturer template search model</param>
        /// <returns>Manufacturer template list model</returns>
        public virtual ManufacturerTemplateListModel PrepareManufacturerTemplateListModel(ManufacturerTemplateSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get manufacturer templates
            var manufacturerTemplates = _manufacturerTemplateService.GetAllManufacturerTemplates();

            //prepare grid model
            var model = new ManufacturerTemplateListModel
            {
                //fill in model values from the entity
                Data  = manufacturerTemplates.PaginationByRequestModel(searchModel).Select(template => template.ToModel()),
                Total = manufacturerTemplates.Count
            };

            return(model);
        }
        /// <summary>
        /// Prepare available manufacturer templates
        /// </summary>
        /// <param name="items">Manufacturer template items</param>
        /// <param name="withSpecialDefaultItem">Whether to insert the first special item for the default value</param>
        /// <param name="defaultItemText">Default item text; pass null to use default value of the default item text</param>
        public virtual void PrepareManufacturerTemplates(IList <SelectListItem> items,
                                                         bool withSpecialDefaultItem = true, string defaultItemText = null)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            //prepare available manufacturer templates
            var availableTemplates = _manufacturerTemplateService.GetAllManufacturerTemplates();

            foreach (var template in availableTemplates)
            {
                items.Add(new SelectListItem {
                    Value = template.Id.ToString(), Text = template.Name
                });
            }

            //insert special item for the default value
            PrepareDefaultItem(items, withSpecialDefaultItem, defaultItemText);
        }
Ejemplo n.º 10
0
        public ActionResult ManufacturerTemplates(GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            var templatesModel = _manufacturerTemplateService.GetAllManufacturerTemplates()
                                 .Select(x => x.ToModel())
                                 .ToList();
            var model = new GridModel <ManufacturerTemplateModel>
            {
                Data  = templatesModel,
                Total = templatesModel.Count
            };

            return(new JsonResult
            {
                Data = model
            });
        }
Ejemplo n.º 11
0
        public Manufacturer Initialize()
        {
            // TODO: cache the default entity.
            var defaultManufacturer = new Manufacturer();

            // Set the first template as the default one.
            var firstTemplate = _manufacturerTemplateService.GetAllManufacturerTemplates().FirstOrDefault();

            if (firstTemplate != null)
            {
                defaultManufacturer.ManufacturerTemplateId = firstTemplate.Id;
            }

            //default values
            defaultManufacturer.PageSize        = 9;
            defaultManufacturer.PageSizeOptions = "9, 25, 50";
            defaultManufacturer.Published       = true;
            defaultManufacturer.AllowCustomersToSelectPageSize = true;

            defaultManufacturer.CreatedOnUtc = DateTime.UtcNow;
            defaultManufacturer.UpdatedOnUtc = DateTime.UtcNow;

            return(defaultManufacturer);
        }
        public ActionResult Manufacturer(int manufacturerId, CatalogSearchQuery query)
        {
            var manufacturer = _manufacturerService.GetManufacturerById(manufacturerId);

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

            // Check whether the current user has a "Manage catalog" permission.
            // It allows him to preview a manufacturer before publishing.
            if (!manufacturer.Published && !Services.Permissions.Authorize(Permissions.Catalog.Manufacturer.Read))
            {
                return(HttpNotFound());
            }

            // ACL (access control list).
            if (!_aclService.Authorize(manufacturer))
            {
                return(HttpNotFound());
            }

            // Store mapping.
            if (!_storeMappingService.Authorize(manufacturer))
            {
                return(HttpNotFound());
            }

            var store    = Services.StoreContext.CurrentStore;
            var customer = Services.WorkContext.CurrentCustomer;

            // 'Continue shopping' URL.
            if (!customer.IsSystemAccount)
            {
                _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastContinueShoppingPage, Services.WebHelper.GetThisPageUrl(false), store.Id);
            }

            var model = manufacturer.ToModel();

            if (query.IsSubPage && !_catalogSettings.ShowDescriptionInSubPages)
            {
                model.Description.ChangeValue(string.Empty);
                model.BottomDescription.ChangeValue(string.Empty);
            }

            model.PictureModel = _helper.PrepareManufacturerPictureModel(manufacturer, model.Name);

            // Featured products.
            var hideFeaturedProducts = _catalogSettings.IgnoreFeaturedProducts || (query.IsSubPage && !_catalogSettings.IncludeFeaturedProductsInSubPages);

            if (!hideFeaturedProducts)
            {
                CatalogSearchResult featuredProductsResult = null;

                var customerRolesIds = customer.CustomerRoleMappings
                                       .Select(x => x.CustomerRole)
                                       .Where(x => x.Active)
                                       .Select(x => x.Id)
                                       .ToList();

                var cacheKey = ModelCacheEventConsumer.MANUFACTURER_HAS_FEATURED_PRODUCTS_KEY.FormatInvariant(manufacturerId, string.Join(",", customerRolesIds), store.Id);
                var hasFeaturedProductsCache = Services.Cache.Get <bool?>(cacheKey);

                var featuredProductsQuery = new CatalogSearchQuery()
                                            .VisibleOnly(customer)
                                            .WithVisibility(ProductVisibility.Full)
                                            .WithManufacturerIds(true, manufacturerId)
                                            .HasStoreId(store.Id)
                                            .WithLanguage(Services.WorkContext.WorkingLanguage)
                                            .WithCurrency(Services.WorkContext.WorkingCurrency);

                if (!hasFeaturedProductsCache.HasValue)
                {
                    featuredProductsResult   = _catalogSearchService.Search(featuredProductsQuery);
                    hasFeaturedProductsCache = featuredProductsResult.TotalHitsCount > 0;
                    Services.Cache.Put(cacheKey, hasFeaturedProductsCache, TimeSpan.FromHours(6));
                }

                if (hasFeaturedProductsCache.Value && featuredProductsResult == null)
                {
                    featuredProductsResult = _catalogSearchService.Search(featuredProductsQuery);
                }

                if (featuredProductsResult != null)
                {
                    // TODO: (mc) determine settings properly
                    var featuredProductsmappingSettings = _helper.GetBestFitProductSummaryMappingSettings(ProductSummaryViewMode.Grid);
                    model.FeaturedProducts = _helper.MapProductSummaryModel(featuredProductsResult.Hits, featuredProductsmappingSettings);
                }
            }

            // Products
            query.WithManufacturerIds(_catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, manufacturerId);

            var searchResult = _catalogSearchService.Search(query);

            model.SearchResult = searchResult;

            var mappingSettings = _helper.GetBestFitProductSummaryMappingSettings(query.GetViewMode());

            model.Products = _helper.MapProductSummaryModel(searchResult.Hits, mappingSettings);

            // Prepare paging/sorting/mode stuff
            _helper.MapListActions(model.Products, manufacturer, _catalogSettings.DefaultPageSizeOptions);

            // Template
            var templateCacheKey = string.Format(ModelCacheEventConsumer.MANUFACTURER_TEMPLATE_MODEL_KEY, manufacturer.ManufacturerTemplateId);
            var templateViewPath = Services.Cache.Get(templateCacheKey, () =>
            {
                var template = _manufacturerTemplateService.GetManufacturerTemplateById(manufacturer.ManufacturerTemplateId);
                if (template == null)
                {
                    template = _manufacturerTemplateService.GetAllManufacturerTemplates().FirstOrDefault();
                }
                return(template.ViewPath);
            });

            //activity log
            Services.CustomerActivity.InsertActivity("PublicStore.ViewManufacturer", T("ActivityLog.PublicStore.ViewManufacturer"), manufacturer.Name);

            Services.DisplayControl.Announce(manufacturer);

            return(View(templateViewPath, model));
        }