public ProductDetailsModel() { DefaultPictureModel = new PictureModel(); PictureModels = new List<PictureModel>(); ProductVariantModels = new List<ProductVariantModel>(); SpecificationAttributeModels = new List<ProductSpecificationModel>(); }
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<CategoryModel>(); }
public ProductVariantModel() { GiftCard = new GiftCardModel(); ProductVariantPrice = new ProductVariantPriceModel(); PictureModel = new PictureModel(); AddToCart = new AddToCartModel(); ProductVariantAttributes = new List<ProductVariantAttributeModel>(); }
public SubCategoryModel() { PictureModel = new PictureModel(); }
public ActionResult Category(int categoryId, CatalogPagingFilteringModel command) { var category = _categoryService.GetCategoryById(categoryId); if (category == null || category.Deleted) return InvokeHttp404(); //Check whether the current user has a "Manage catalog" permission //It allows him to preview a category before publishing if (!category.Published && !_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) return InvokeHttp404(); //ACL (access control list) if (!_aclService.Authorize(category)) return InvokeHttp404(); //Store mapping if (!_storeMappingService.Authorize(category)) return InvokeHttp404(); //'Continue shopping' URL _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer, SystemCustomerAttributeNames.LastContinueShoppingPage, _webHelper.GetThisPageUrl(false), _storeContext.CurrentStore.Id); if (command.PageNumber <= 0) command.PageNumber = 1; var model = category.ToModel(); //sorting model.PagingFilteringContext.AllowProductSorting = _catalogSettings.AllowProductSorting; if (model.PagingFilteringContext.AllowProductSorting) { foreach (ProductSortingEnum enumValue in Enum.GetValues(typeof(ProductSortingEnum))) { var currentPageUrl = _webHelper.GetThisPageUrl(true); var sortUrl = _webHelper.ModifyQueryString(currentPageUrl, "orderby=" + ((int)enumValue).ToString(), null); var sortValue = enumValue.GetLocalizedEnum(_localizationService, _workContext); model.PagingFilteringContext.AvailableSortOptions.Add(new SelectListItem() { Text = sortValue, Value = sortUrl, Selected = enumValue == (ProductSortingEnum)command.OrderBy }); } } //view mode model.PagingFilteringContext.AllowProductViewModeChanging = _catalogSettings.AllowProductViewModeChanging; var viewMode = !string.IsNullOrEmpty(command.ViewMode) ? command.ViewMode : _catalogSettings.DefaultViewMode; if (model.PagingFilteringContext.AllowProductViewModeChanging) { var currentPageUrl = _webHelper.GetThisPageUrl(true); //grid model.PagingFilteringContext.AvailableViewModes.Add(new SelectListItem() { Text = _localizationService.GetResource("Categories.ViewMode.Grid"), Value = _webHelper.ModifyQueryString(currentPageUrl, "viewmode=grid", null), Selected = viewMode == "grid" }); //list model.PagingFilteringContext.AvailableViewModes.Add(new SelectListItem() { Text = _localizationService.GetResource("Categories.ViewMode.List"), Value = _webHelper.ModifyQueryString(currentPageUrl, "viewmode=list", null), Selected = viewMode == "list" }); } //page size model.PagingFilteringContext.AllowCustomersToSelectPageSize = false; if (category.AllowCustomersToSelectPageSize && category.PageSizeOptions != null) { var pageSizes = category.PageSizeOptions.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (pageSizes.Any()) { // get the first page size entry to use as the default (category page load) or if customer enters invalid value via query string if (command.PageSize <= 0 || !pageSizes.Contains(command.PageSize.ToString())) { int temp = 0; if (int.TryParse(pageSizes.FirstOrDefault(), out temp)) { if (temp > 0) { command.PageSize = temp; } } } var currentPageUrl = _webHelper.GetThisPageUrl(true); var sortUrl = _webHelper.ModifyQueryString(currentPageUrl, "pagesize={0}", null); sortUrl = _webHelper.RemoveQueryString(sortUrl, "pagenumber"); foreach (var pageSize in pageSizes) { int temp = 0; if (!int.TryParse(pageSize, out temp)) { continue; } if (temp <= 0) { continue; } model.PagingFilteringContext.PageSizeOptions.Add(new SelectListItem() { Text = pageSize, Value = String.Format(sortUrl, pageSize), Selected = pageSize.Equals(command.PageSize.ToString(), StringComparison.InvariantCultureIgnoreCase) }); } if (model.PagingFilteringContext.PageSizeOptions.Any()) { model.PagingFilteringContext.PageSizeOptions = model.PagingFilteringContext.PageSizeOptions.OrderBy(x => int.Parse(x.Text)).ToList(); model.PagingFilteringContext.AllowCustomersToSelectPageSize = true; if (command.PageSize <= 0) { command.PageSize = int.Parse(model.PagingFilteringContext.PageSizeOptions.FirstOrDefault().Text); } } } } else { //customer is not allowed to select a page size command.PageSize = category.PageSize; } if (command.PageSize <= 0) command.PageSize = category.PageSize; //price ranges model.PagingFilteringContext.PriceRangeFilter.LoadPriceRangeFilters(category.PriceRanges, _webHelper, _priceFormatter); var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_webHelper, category.PriceRanges); decimal? minPriceConverted = null; decimal? maxPriceConverted = null; if (selectedPriceRange != null) { if (selectedPriceRange.From.HasValue) minPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.From.Value, _workContext.WorkingCurrency); if (selectedPriceRange.To.HasValue) maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, _workContext.WorkingCurrency); } //category breadcrumb model.DisplayCategoryBreadcrumb = _catalogSettings.CategoryBreadcrumbEnabled; if (model.DisplayCategoryBreadcrumb) { foreach (var catBr in GetCategoryBreadCrumb(category)) { model.CategoryBreadcrumb.Add(new CategoryModel() { Id = catBr.Id, Name = catBr.GetLocalized(x => x.Name), SeName = catBr.GetSeName() }); } } //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, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); subCatModel.PictureModel = _cacheManager.Get(categoryPictureCacheKey, () => { var pictureModel = new PictureModel() { FullSizeImageUrl = _pictureService.GetPictureUrl(x.PictureId), ImageUrl = _pictureService.GetPictureUrl(x.PictureId, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatName), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatName) }; return pictureModel; }); return subCatModel; }) .ToList(); //featured products //Question: should we use '_catalogSettings.ShowProductsFromSubcategories' setting for displaying featured products? if (!_catalogSettings.IgnoreFeaturedProducts && _categoryService.GetTotalNumberOfFeaturedProducts(categoryId) > 0) { //We use the fast GetTotalNumberOfFeaturedProducts before invoking of the slow SearchProducts //to ensure that we have at least one featured product var featuredProducts = _productService.SearchProducts( categoryIds: new List<int>() { category.Id }, storeId: _storeContext.CurrentStore.Id, featuredProducts: true); model.FeaturedProducts = PrepareProductOverviewModels(featuredProducts).ToList(); } var categoryIds = new List<int>(); categoryIds.Add(category.Id); if (_catalogSettings.ShowProductsFromSubcategories) { //include subcategories categoryIds.AddRange(GetChildCategoryIds(category.Id)); } //products IList<int> alreadyFilteredSpecOptionIds = model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds(_webHelper); IList<int> filterableSpecificationAttributeOptionIds = null; var products = _productService.SearchProducts(out filterableSpecificationAttributeOptionIds, true, categoryIds: categoryIds, storeId: _storeContext.CurrentStore.Id, featuredProducts:_catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, priceMin:minPriceConverted, priceMax:maxPriceConverted, filteredSpecs: alreadyFilteredSpecOptionIds, orderBy: (ProductSortingEnum)command.OrderBy, pageIndex: command.PageNumber - 1, pageSize: command.PageSize); model.Products = PrepareProductOverviewModels(products).ToList(); model.PagingFilteringContext.LoadPagedList(products); model.PagingFilteringContext.ViewMode = viewMode; //specs model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds, filterableSpecificationAttributeOptionIds, _specificationAttributeService, _webHelper, _workContext); //template var templateCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_TEMPLATE_MODEL_KEY, category.CategoryTemplateId); var templateViewPath = _cacheManager.Get(templateCacheKey, () => { var template = _categoryTemplateService.GetCategoryTemplateById(category.CategoryTemplateId); if (template == null) template = _categoryTemplateService.GetAllCategoryTemplates().FirstOrDefault(); if (template == null) throw new Exception("No default template could be loaded"); return template.ViewPath; }); //activity log _customerActivityService.InsertActivity("PublicStore.ViewCategory", _localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name); return View(templateViewPath, model); }
public ShoppingCartItemModel() { Picture = new PictureModel(); AllowedQuantities = new List<SelectListItem>(); Warnings = new List<string>(); }
protected IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(IEnumerable<Product> products, bool preparePriceModel = true, bool preparePictureModel = true, int? productThumbPictureSize = null, bool prepareSpecificationAttributes = false, bool forceRedirectionAfterAddingToCart = false) { if (products == null) throw new ArgumentNullException("products"); //performance optimization. let's load all variants at one go var allVariants = _productService.GetProductVariantsByProductIds(products.Select(x => x.Id).ToArray()); var models = new List<ProductOverviewModel>(); foreach (var product in products) { var model = new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }; //price if (preparePriceModel) { #region Prepare product price var priceModel = new ProductOverviewModel.ProductPriceModel(); //var productVariants = _productService.GetProductVariantsByProductId(product.Id); //we use already loaded variants var productVariants = allVariants.Where(x => x.ProductId == product.Id).ToList(); switch (productVariants.Count) { case 0: { //no variants priceModel.OldPrice = null; priceModel.Price = null; } break; default: { if (_permissionService.Authorize(StandardPermissionProvider.DisplayPrices)) { //calculate for the maximum quantity (in case if we have tier prices) decimal? minimalPrice = null; var productVariant = _priceCalculationService.GetProductVariantWithMinimalPrice(productVariants, _workContext.CurrentCustomer, true, int.MaxValue, out minimalPrice); if (!productVariant.CustomerEntersPrice) { if (productVariant.CallForPrice) { priceModel.OldPrice = null; priceModel.Price = _localizationService.GetResource("Products.CallForPrice"); } else if (minimalPrice.HasValue) { //calculate prices decimal taxRate = decimal.Zero; decimal oldPriceBase = _taxService.GetProductPrice(productVariant, productVariant.OldPrice, out taxRate); decimal finalPriceBase = _taxService.GetProductPrice(productVariant, minimalPrice.Value, out taxRate); decimal oldPrice = _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase, _workContext.WorkingCurrency); decimal finalPrice = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceBase, _workContext.WorkingCurrency); //do we have tier prices configured? var tierPrices = new List<TierPrice>(); if (productVariant.HasTierPrices) { tierPrices.AddRange(productVariant.TierPrices .OrderBy(tp => tp.Quantity) .ToList() .FilterForCustomer(_workContext.CurrentCustomer) .RemoveDuplicatedQuantities()); } bool displayFromMessage = //When there is just one tier (with qty 1), there are no actual savings in the list. (tierPrices.Count > 0 && !(tierPrices.Count == 1 && tierPrices[0].Quantity <= 1)) || //we have more than one variant (productVariants.Count > 1); if (displayFromMessage) { priceModel.OldPrice = null; priceModel.Price = String.Format(_localizationService.GetResource("Products.PriceRangeFrom"), _priceFormatter.FormatPrice(finalPrice)); } else { if (finalPriceBase != oldPriceBase && oldPriceBase != decimal.Zero) { priceModel.OldPrice = _priceFormatter.FormatPrice(oldPrice); priceModel.Price = _priceFormatter.FormatPrice(finalPrice); } else { priceModel.OldPrice = null; priceModel.Price = _priceFormatter.FormatPrice(finalPrice); } } } else { //Actually it's not possible (we presume that minimalPrice always has a value) //We never should get here Debug.WriteLine(string.Format("Cannot calculate minPrice for product variant #{0}", productVariant.Id)); } } } else { //hide prices priceModel.OldPrice = null; priceModel.Price = null; } } break; } //'add to cart' button switch (productVariants.Count) { case 0: { // no variants priceModel.DisableBuyButton = true; priceModel.DisableWishlistButton = true; priceModel.AvailableForPreOrder = false; } break; case 1: { //only one variant var productVariant = productVariants[0]; //add to car button priceModel.DisableBuyButton = productVariant.DisableBuyButton || !_permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart); if (!_permissionService.Authorize(StandardPermissionProvider.DisplayPrices)) { priceModel.DisableBuyButton = true; } //add to wishlist button priceModel.DisableWishlistButton = productVariant.DisableWishlistButton || !_permissionService.Authorize(StandardPermissionProvider.EnableWishlist); if (!_permissionService.Authorize(StandardPermissionProvider.DisplayPrices)) { priceModel.DisableWishlistButton = true; } priceModel.AvailableForPreOrder = productVariant.AvailableForPreOrder; } break; default: { //multiple variants priceModel.DisableBuyButton = true; priceModel.DisableWishlistButton = true; priceModel.AvailableForPreOrder = false; } break; } priceModel.ForceRedirectionAfterAddingToCart = forceRedirectionAfterAddingToCart; model.ProductPrice = priceModel; #endregion } //picture if (preparePictureModel) { #region Prepare product picture //If a size has been set in the view, we use it in priority int pictureSize = productThumbPictureSize.HasValue ? productThumbPictureSize.Value : _mediaSettings.ProductThumbPictureSize; //prepare picture model var defaultProductPictureCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_DEFAULTPICTURE_MODEL_KEY, product.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); model.DefaultPictureModel = _cacheManager.Get(defaultProductPictureCacheKey, () => { var picture = product.GetDefaultProductPicture(_pictureService); var pictureModel = new PictureModel() { ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize), FullSizeImageUrl = _pictureService.GetPictureUrl(picture), Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name) }; return pictureModel; }); #endregion } //specs if (prepareSpecificationAttributes) { //specs for comparing model.SpecificationAttributeModels = PrepareProductSpecificationModel(product); } models.Add(model); } return models; }
public ActionResult ManufacturerAll() { var model = new List<ManufacturerModel>(); var manufacturers = _manufacturerService.GetAllManufacturers(); foreach (var manufacturer in manufacturers) { var modelMan = manufacturer.ToModel(); //prepare picture model int pictureSize = _mediaSettings.ManufacturerThumbPictureSize; var manufacturerPictureCacheKey = string.Format(ModelCacheEventConsumer.MANUFACTURER_PICTURE_MODEL_KEY, manufacturer.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); modelMan.PictureModel = _cacheManager.Get(manufacturerPictureCacheKey, () => { var pictureModel = new PictureModel() { FullSizeImageUrl = _pictureService.GetPictureUrl(manufacturer.PictureId), ImageUrl = _pictureService.GetPictureUrl(manufacturer.PictureId, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Manufacturer.ImageLinkTitleFormat"), modelMan.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Manufacturer.ImageAlternateTextFormat"), modelMan.Name) }; return pictureModel; }); model.Add(modelMan); } return View(model); }
public ActionResult HomepageCategories() { var categories = _categoryService.GetAllCategoriesDisplayedOnHomePage() .Where(c => _aclService.Authorize(c) && _storeMappingService.Authorize(c)) .ToList(); var listModel = categories .Select(x => { var catModel = x.ToModel(); //prepare picture model int pictureSize = _mediaSettings.CategoryThumbPictureSize; var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, x.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); catModel.PictureModel = _cacheManager.Get(categoryPictureCacheKey, () => { var pictureModel = new PictureModel() { FullSizeImageUrl = _pictureService.GetPictureUrl(x.PictureId), ImageUrl = _pictureService.GetPictureUrl(x.PictureId, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), catModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), catModel.Name) }; return pictureModel; }); return catModel; }) .ToList(); return PartialView(listModel); }
public ProductOverviewModel() { ProductPrice = new ProductPriceModel(); DefaultPictureModel = new PictureModel(); SpecificationAttributeModels = new List<ProductSpecificationModel>(); }
public ShoppingCartItemModel() { Picture = new PictureModel(); }