public ManufacturerModel() { PictureModel = new PictureModel(); FeaturedProducts = new List<ProductOverviewModel>(); Products = new List<ProductOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); }
public CategoryModel() { PictureModel = new PictureModel(); FeaturedProducts = new List<ProductOverviewModel>(); Products = new List<ProductOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); SubCategories = new List<SubCategoryModel>(); CategoryBreadcrumb = new List<MenuItem>(); }
public CategoryModel() { PictureModel = new PictureModel(); FeaturedProducts = new List <ProductOverviewModel>(); Products = new List <ProductOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); SubCategories = new List <SubCategoryModel>(); CategoryBreadcrumb = new List <CategoryModel>(); }
public ProductOverviewModel() { ProductPrice = new ProductPriceModel(); DefaultPictureModel = new PictureModel(); SpecificationAttributeModels = new List<ProductSpecificationModel>(); Manufacturers = new List<ManufacturerOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); ColorAttributes = new List<ColorAttributeModel>(); Weight = ""; TransportSurcharge = ""; }
public ProductOverviewModel() { ProductPrice = new ProductPriceModel(); DefaultPictureModel = new PictureModel(); SpecificationAttributeModels = new List <ProductSpecificationModel>(); Manufacturers = new List <ManufacturerOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); ColorAttributes = new List <ColorAttributeModel>(); Weight = ""; TransportSurcharge = ""; }
public ActionResult RecentlyAddedProducts(CatalogPagingFilteringModel command) { var model = new RecentlyAddedProductsModel(); if (_catalogSettings.RecentlyAddedProductsEnabled) { IList<int> filterableSpecificationAttributeOptionIds = null; var ctx = new ProductSearchContext(); ctx.LanguageId = _services.WorkContext.WorkingLanguage.Id; //ctx.OrderBy = (ProductSortingEnum)command.OrderBy; ctx.OrderBy = ProductSortingEnum.CreatedOn; //ctx.PageSize = command.PageSize; ctx.PageSize = _catalogSettings.RecentlyAddedProductsNumber; //ctx.PageIndex = command.PageNumber - 1; ctx.FilterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIds; ctx.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; ctx.VisibleIndividuallyOnly = true; var products = _productService.SearchProducts(ctx); //var products = _productService.SearchProducts(ctx).Take(_catalogSettings.RecentlyAddedProductsNumber).OrderBy((ProductSortingEnum)command.OrderBy); model.Products.AddRange(_helper.PrepareProductOverviewModels(products)); //model.PagingFilteringContext.LoadPagedList(products); } return View(model); }
public ActionResult ProductsByTag(int productTagId, CatalogPagingFilteringModel command) { var productTag = _productTagService.GetProductTagById(productTagId); if (productTag == null) return HttpNotFound(); if (command.PageNumber <= 0) command.PageNumber = 1; var model = new ProductsByTagModel() { Id = productTag.Id, TagName = productTag.GetLocalized(y => y.Name) }; if (command.OrderBy == (int)ProductSortingEnum.Initial) { command.OrderBy = (int)_catalogSettings.DefaultSortOrder; } _helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext { AllowCustomersToSelectPageSize = _catalogSettings.ProductsByTagAllowCustomersToSelectPageSize, PageSize = _catalogSettings.ProductsByTagPageSize, PageSizeOptions = _catalogSettings.ProductsByTagPageSizeOptions.IsEmpty() ? _catalogSettings.DefaultPageSizeOptions : _catalogSettings.ProductsByTagPageSizeOptions }); //products var ctx = new ProductSearchContext(); ctx.ProductTagId = productTag.Id; ctx.LanguageId = _services.WorkContext.WorkingLanguage.Id; ctx.OrderBy = (ProductSortingEnum)command.OrderBy; ctx.PageIndex = command.PageNumber - 1; ctx.PageSize = command.PageSize; ctx.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; ctx.VisibleIndividuallyOnly = true; var products = _productService.SearchProducts(ctx); model.Products = _helper.PrepareProductOverviewModels( products, prepareColorAttributes: true, prepareManufacturers: command.ViewMode.IsCaseInsensitiveEqual("list")).ToList(); model.PagingFilteringContext.LoadPagedList(products); //model.PagingFilteringContext.ViewMode = viewMode; return View(model); }
public ActionResult Manufacturer(int manufacturerId, CatalogPagingFilteringModel command) { 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(StandardPermissionProvider.ManageCatalog)) return HttpNotFound(); //Store mapping if (!_storeMappingService.Authorize(manufacturer)) return HttpNotFound(); //'Continue shopping' URL _genericAttributeService.SaveAttribute(_services.WorkContext.CurrentCustomer, SystemCustomerAttributeNames.LastContinueShoppingPage, _services.WebHelper.GetThisPageUrl(false), _services.StoreContext.CurrentStore.Id); if (command.PageNumber <= 0) command.PageNumber = 1; var model = manufacturer.ToModel(); // prepare picture model model.PictureModel = _helper.PrepareManufacturerPictureModel(manufacturer, model.Name); if (command.OrderBy == (int)ProductSortingEnum.Initial) { command.OrderBy = (int)_catalogSettings.DefaultSortOrder; } _helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext { AllowCustomersToSelectPageSize = manufacturer.AllowCustomersToSelectPageSize, PageSize = manufacturer.PageSize, PageSizeOptions = manufacturer.PageSizeOptions }); //price ranges model.PagingFilteringContext.PriceRangeFilter.LoadPriceRangeFilters(manufacturer.PriceRanges, _services.WebHelper, _priceFormatter); var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_services.WebHelper, manufacturer.PriceRanges); decimal? minPriceConverted = null; decimal? maxPriceConverted = null; if (selectedPriceRange != null) { if (selectedPriceRange.From.HasValue) minPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.From.Value, _services.WorkContext.WorkingCurrency); if (selectedPriceRange.To.HasValue) maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, _services.WorkContext.WorkingCurrency); } var customerRolesIds = _services.WorkContext.CurrentCustomer.CustomerRoles.Where(x => x.Active).Select(x => x.Id).ToList(); // Featured products if (!_catalogSettings.IgnoreFeaturedProducts) { IPagedList<Product> featuredProducts = null; string cacheKey = ModelCacheEventConsumer.MANUFACTURER_HAS_FEATURED_PRODUCTS_KEY.FormatInvariant(manufacturerId, string.Join(",", customerRolesIds), _services.StoreContext.CurrentStore.Id); var hasFeaturedProductsCache = _services.Cache.Get<bool?>(cacheKey); var ctx = new ProductSearchContext(); ctx.ManufacturerId = manufacturer.Id; ctx.FeaturedProducts = true; ctx.LanguageId = _services.WorkContext.WorkingLanguage.Id; ctx.OrderBy = ProductSortingEnum.Position; ctx.PageSize = int.MaxValue; ctx.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; ctx.VisibleIndividuallyOnly = true; if (!hasFeaturedProductsCache.HasValue) { featuredProducts = _productService.SearchProducts(ctx); hasFeaturedProductsCache = featuredProducts.TotalCount > 0; _services.Cache.Set(cacheKey, hasFeaturedProductsCache, 240); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { featuredProducts = _productService.SearchProducts(ctx); } if (featuredProducts != null) { model.FeaturedProducts = _helper.PrepareProductOverviewModels(featuredProducts, prepareColorAttributes: true).ToList(); } } //products var ctx2 = new ProductSearchContext(); ctx2.ManufacturerId = manufacturer.Id; ctx2.FeaturedProducts = _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false; ctx2.PriceMin = minPriceConverted; ctx2.PriceMax = maxPriceConverted; ctx2.LanguageId = _services.WorkContext.WorkingLanguage.Id; ctx2.OrderBy = (ProductSortingEnum)command.OrderBy; ctx2.PageIndex = command.PageNumber - 1; ctx2.PageSize = command.PageSize; ctx2.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; ctx2.VisibleIndividuallyOnly = true; var products = _productService.SearchProducts(ctx2); model.Products = _helper.PrepareProductOverviewModels( products, prepareColorAttributes: false, prepareManufacturers: command.ViewMode.IsCaseInsensitiveEqual("list")).ToList(); model.PagingFilteringContext.LoadPagedList(products); //model.PagingFilteringContext.ViewMode = viewMode; //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); return View(templateViewPath, model); }
public ActionResult Category(int categoryId, CatalogPagingFilteringModel command, string filter) { var category = _categoryService.GetCategoryById(categoryId); if (category == null || category.Deleted) return HttpNotFound(); //Check whether the current user has a "Manage catalog" permission //It allows him to preview a category before publishing if (!category.Published && !_services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog)) return HttpNotFound(); //ACL (access control list) if (!_aclService.Authorize(category)) return HttpNotFound(); //Store mapping if (!_storeMappingService.Authorize(category)) return HttpNotFound(); //'Continue shopping' URL _genericAttributeService.SaveAttribute(_services.WorkContext.CurrentCustomer, SystemCustomerAttributeNames.LastContinueShoppingPage, _services.WebHelper.GetThisPageUrl(false), _services.StoreContext.CurrentStore.Id); if (command.PageNumber <= 0) command.PageNumber = 1; if (command.ViewMode.IsEmpty() && category.DefaultViewMode.HasValue()) { command.ViewMode = category.DefaultViewMode; } if (command.OrderBy == (int)ProductSortingEnum.Initial) { command.OrderBy = (int)_catalogSettings.DefaultSortOrder; } var model = category.ToModel(); _helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext { AllowCustomersToSelectPageSize = category.AllowCustomersToSelectPageSize, PageSize = category.PageSize, PageSizeOptions = category.PageSizeOptions }); //price ranges model.PagingFilteringContext.PriceRangeFilter.LoadPriceRangeFilters(category.PriceRanges, _services.WebHelper, _priceFormatter); var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_services.WebHelper, category.PriceRanges); decimal? minPriceConverted = null; decimal? maxPriceConverted = null; if (selectedPriceRange != null) { if (selectedPriceRange.From.HasValue) minPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.From.Value, _services.WorkContext.WorkingCurrency); if (selectedPriceRange.To.HasValue) maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, _services.WorkContext.WorkingCurrency); } //category breadcrumb model.DisplayCategoryBreadcrumb = _catalogSettings.CategoryBreadcrumbEnabled; if (model.DisplayCategoryBreadcrumb) { model.CategoryBreadcrumb = _helper.GetCategoryBreadCrumb(category.Id, 0); } model.DisplayFilter = _catalogSettings.FilterEnabled; model.SubCategoryDisplayType = _catalogSettings.SubCategoryDisplayType; var customerRolesIds = _services.WorkContext.CurrentCustomer.CustomerRoles.Where(x => x.Active).Select(x => x.Id).ToList(); // subcategories model.SubCategories = _categoryService .GetAllCategoriesByParentCategoryId(categoryId) .Select(x => { var subCatName = x.GetLocalized(y => y.Name); var subCatModel = new CategoryModel.SubCategoryModel { Id = x.Id, Name = subCatName, SeName = x.GetSeName(), }; //prepare picture model int pictureSize = _mediaSettings.CategoryThumbPictureSize; var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, x.Id, pictureSize, true, _services.WorkContext.WorkingLanguage.Id, _services.WebHelper.IsCurrentConnectionSecured(), _services.StoreContext.CurrentStore.Id); subCatModel.PictureModel = _services.Cache.Get(categoryPictureCacheKey, () => { var picture = _pictureService.GetPictureById(x.PictureId.GetValueOrDefault()); var pictureModel = new PictureModel() { PictureId = x.PictureId.GetValueOrDefault(), FullSizeImageUrl = _pictureService.GetPictureUrl(picture), ImageUrl = _pictureService.GetPictureUrl(picture, targetSize: pictureSize), Title = string.Format(T("Media.Category.ImageLinkTitleFormat"), subCatName), AlternateText = string.Format(T("Media.Category.ImageAlternateTextFormat"), subCatName) }; return pictureModel; }); return subCatModel; }) .ToList(); // Featured products if (!_catalogSettings.IgnoreFeaturedProducts) { IPagedList<Product> featuredProducts = null; string cacheKey = ModelCacheEventConsumer.CATEGORY_HAS_FEATURED_PRODUCTS_KEY.FormatInvariant(categoryId, string.Join(",", customerRolesIds), _services.StoreContext.CurrentStore.Id); var hasFeaturedProductsCache = _services.Cache.Get<bool?>(cacheKey); var ctx = new ProductSearchContext(); if (category.Id > 0) ctx.CategoryIds.Add(category.Id); ctx.FeaturedProducts = true; ctx.LanguageId = _services.WorkContext.WorkingLanguage.Id; ctx.OrderBy = ProductSortingEnum.Position; ctx.PageSize = int.MaxValue; ctx.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; ctx.VisibleIndividuallyOnly = true; ctx.Origin = categoryId.ToString(); if (!hasFeaturedProductsCache.HasValue) { featuredProducts = _productService.SearchProducts(ctx); hasFeaturedProductsCache = featuredProducts.TotalCount > 0; _services.Cache.Set(cacheKey, hasFeaturedProductsCache, 240); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { featuredProducts = _productService.SearchProducts(ctx); } if (featuredProducts != null) { model.FeaturedProducts = _helper.PrepareProductOverviewModels( featuredProducts, prepareColorAttributes: true).ToList(); } } // Products if (filter.HasValue()) { var context = new FilterProductContext { ParentCategoryID = category.Id, CategoryIds = new List<int> { category.Id }, Criteria = _filterService.Deserialize(filter), OrderBy = command.OrderBy }; if (_catalogSettings.ShowProductsFromSubcategories) context.CategoryIds.AddRange(_helper.GetChildCategoryIds(category.Id)); var filterQuery = _filterService.ProductFilter(context); var products = new PagedList<Product>(filterQuery, command.PageIndex, command.PageSize); model.Products = _helper.PrepareProductOverviewModels( products, prepareColorAttributes: true, prepareManufacturers: command.ViewMode.IsCaseInsensitiveEqual("list")).ToList(); model.PagingFilteringContext.LoadPagedList(products); } else { // use old filter IList<int> alreadyFilteredSpecOptionIds = model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds(_services.WebHelper); var ctx2 = new ProductSearchContext(); if (category.Id > 0) { ctx2.CategoryIds.Add(category.Id); if (_catalogSettings.ShowProductsFromSubcategories) { // include subcategories ctx2.CategoryIds.AddRange(_helper.GetChildCategoryIds(category.Id)); } } ctx2.FeaturedProducts = _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false; ctx2.PriceMin = minPriceConverted; ctx2.PriceMax = maxPriceConverted; ctx2.LanguageId = _services.WorkContext.WorkingLanguage.Id; ctx2.FilteredSpecs = alreadyFilteredSpecOptionIds; ctx2.OrderBy = (ProductSortingEnum)command.OrderBy; // ProductSortingEnum.Position; ctx2.PageIndex = command.PageNumber - 1; ctx2.PageSize = command.PageSize; ctx2.LoadFilterableSpecificationAttributeOptionIds = true; ctx2.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; ctx2.VisibleIndividuallyOnly = true; ctx2.Origin = categoryId.ToString(); var products = _productService.SearchProducts(ctx2); model.Products = _helper.PrepareProductOverviewModels( products, prepareColorAttributes: true, prepareManufacturers: command.ViewMode.IsCaseInsensitiveEqual("list")).ToList(); model.PagingFilteringContext.LoadPagedList(products); //model.PagingFilteringContext.ViewMode = viewMode; //specs model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds, ctx2.FilterableSpecificationAttributeOptionIds, _specificationAttributeService, _services.WebHelper, _services.WorkContext); } // template var templateCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_TEMPLATE_MODEL_KEY, category.CategoryTemplateId); var templateViewPath = _services.Cache.Get(templateCacheKey, () => { var template = _categoryTemplateService.GetCategoryTemplateById(category.CategoryTemplateId); if (template == null) template = _categoryTemplateService.GetAllCategoryTemplates().FirstOrDefault(); return template.ViewPath; }); // activity log _services.CustomerActivity.InsertActivity("PublicStore.ViewCategory", T("ActivityLog.PublicStore.ViewCategory"), category.Name); return View(templateViewPath, model); }
public ProductsByTagModel() { Products = new List <ProductOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); }
public RecentlyAddedProductsModel() { Products = new List <ProductOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); }
public ActionResult ProductsByTag(int productTagId, CatalogPagingFilteringModel command) { var productTag = _productTagService.GetProductTagById(productTagId); if (productTag == null) return RedirectToRoute("HomePage"); if (command.PageNumber <= 0) command.PageNumber = 1; var model = new ProductsByTagModel() { Id = productTag.Id, TagName = productTag.GetLocalized(y => y.Name) }; // codehint: sm-edit (replaced) PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext { AllowCustomersToSelectPageSize = _catalogSettings.ProductsByTagAllowCustomersToSelectPageSize, PageSize = _catalogSettings.ProductsByTagPageSize, PageSizeOptions = _catalogSettings.ProductsByTagPageSizeOptions.IsEmpty() ? _catalogSettings.DefaultPageSizeOptions : _catalogSettings.ProductsByTagPageSizeOptions }); //products var ctx = new ProductSearchContext(); ctx.ProductTagId = productTag.Id; ctx.LanguageId = _workContext.WorkingLanguage.Id; ctx.OrderBy = (ProductSortingEnum)command.OrderBy; ctx.PageIndex = command.PageNumber - 1; ctx.PageSize = command.PageSize; ctx.StoreId = _storeContext.CurrentStoreIdIfMultiStoreMode; ctx.VisibleIndividuallyOnly = true; var products = _productService.SearchProducts(ctx); model.Products = PrepareProductOverviewModels(products, prepareColorAttributes: true).ToList(); model.PagingFilteringContext.LoadPagedList(products); //model.PagingFilteringContext.ViewMode = viewMode; // codehint: sm-delete return View(model); }
public ProductsByTagModel() { Products = new List<ProductOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); }
public RecentlyAddedProductsModel() { Products = new List<ProductOverviewModel>(); PagingFilteringContext = new CatalogPagingFilteringModel(); }