//category public static CategoryModel ToModel(this Category entity) { if (entity == null) return null; var model = new CategoryModel() { Id = entity.Id, Name = entity.GetLocalized(x => x.Name), Description = entity.GetLocalized(x => x.Description), MetaKeywords = entity.GetLocalized(x => x.MetaKeywords), MetaDescription = entity.GetLocalized(x => x.MetaDescription), MetaTitle = entity.GetLocalized(x => x.MetaTitle), SeName = entity.GetSeName(), }; return model; }
public ActionResult SearchByCatgory() { string categoryCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_MENU_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var cachedCategoriesModel = _cacheManager.Get(categoryCacheKey, () => PrepareCategorySimpleModels(0)); List<CategoryModel> CheckList = new List<CategoryModel>(); foreach (var data in cachedCategoriesModel) { CategoryModel custom = new CategoryModel(); custom.Id = data.Id; custom.Name = data.Name; custom.SeName = data.SeName; custom.Description = data.Description; custom.MetaDescription = data.MetaDescription; custom.SubCategories = data.SubCategories.Select(x => new Nop.Web.Models.Catalog.CategoryModel.SubCategoryModel { Name = x.Name, SeName = x.SeName, PictureModel = CustomPictureModelDetail(x.Id, x.Name) }).ToList(); custom.PictureModel = CustomPictureModelDetail(data.Id, data.Name); CheckList.Add(custom); } SearchBoxModel Searching = new SearchBoxModel(); Searching.AutoCompleteEnabled = _catalogSettings.ProductSearchAutoCompleteEnabled; Searching.ShowProductImagesInSearchAutoComplete = _catalogSettings.ShowProductImagesInSearchAutoComplete; Searching.SearchTermMinimumLength = _catalogSettings.ProductSearchTermMinimumLength; ViewBag.HomePageCatgoryList = CheckList.ToList(); return PartialView(Searching); }
public ActionResult HomePageCatgoryBoxDetails() { string categoryCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_MENU_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var cachedCategoriesModel = _cacheManager.Get(categoryCacheKey, () => PrepareCategorySimpleModels(0)); List<CategoryModel> CheckList = new List<CategoryModel>(); foreach (var data in cachedCategoriesModel) { CategoryModel custom = new CategoryModel(); custom.Name = data.Name; custom.SeName = data.SeName; custom.Description = data.Description; custom.MetaDescription = data.MetaDescription; custom.SubCategories = data.SubCategories.Select(x => new Nop.Web.Models.Catalog.CategoryModel.SubCategoryModel { Name = x.Name, SeName = x.SeName, PictureModel = CustomPictureModelDetail(x.PictureId, x.Name) }).ToList(); custom.PictureModel = CustomPictureModelDetail(data.PictureId, data.Name); CheckList.Add(custom); } return PartialView(CheckList); }
public CategoryManufacturerModel() { Manufacturers = new List <ManufacturerModel>(); Category = new CategoryModel(); }
public string RenderProductview(CategoryModel model) { ArrayList newarray = new ArrayList(); string outputhtml = ""; string viewname = "_ProductBox"; if (model.PagingFilteringContext.ViewMode.ToLower() == "list") { foreach (var data in model.Products) { viewname = "_ProductListBox"; outputhtml += "<div class='item-box'>" + PartialViewdata(this, viewname, data) + "</div>"; } } else { foreach (var data in model.Products) { outputhtml += "<div class='col-md-6 col-sm-6'><div class='item-box'>" + PartialViewdata(this, viewname, data) + "</div></div>"; } } return outputhtml; }
public ActionResult HomepageCategoryContainer() { string categoriesCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_HOMEPAGE_KEY, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured()); var model = _cacheManager.Get(categoriesCacheKey, () => _categoryService.GetAllCategoriesDisplayedInTopMenu() .Where(x => x.ShowOnHomePage == false && x.IncludeInTopMenu == true) .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 picture = _pictureService.GetPictureById(x.PictureId); var pictureModel = new PictureModel { FullSizeImageUrl = _pictureService.GetPictureUrl(picture), ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), catModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), catModel.Name) }; return pictureModel; }); //get subcategories var subcats = _categoryService.GetAllCategoriesByParentCategoryId(catModel.Id); IList<CategoryModel.SubCategoryModel> lstSubcategories = new List<CategoryModel.SubCategoryModel>(); //add parent products IList<int> categoryId = new List<int>(); categoryId.Add(catModel.Id); foreach (Category subcatitem in subcats) { categoryId.Add(subcatitem.Id); var subsubcats = _categoryService.GetAllCategoriesByParentCategoryId(subcatitem.Id); foreach (Category subsubcatitem in subsubcats) { categoryId.Add(subsubcatitem.Id); } } //include child products in the list since not all parents have products attached var parentProducts = _productService.SearchProducts(0, 12, categoryId, 0, 0, 0, 0, null, false, null, null, null, 0, null, false, true, false, 0, null, ProductSortingEnum.NameAsc, false, null); IList<ProductOverviewModel> lstParentProducts = new List<ProductOverviewModel>(); int counter = 0; foreach (Product parentPItem in parentProducts) { if (counter < 8) { ProductOverviewModel p = new ProductOverviewModel(); decimal convertedPrice = Math.Round(parentPItem.Price, 2); p.ProductPrice.Price = convertedPrice.ToString(); p.Id = parentPItem.Id; p.Name = parentPItem.Name; p.SeName = parentPItem.GetSeName(); p.ShortDescription = parentPItem.ShortDescription; p.ProductPrice.OldPrice = parentPItem.OldPrice.ToString(); var picture = _pictureService.GetPicturesByProductId(parentPItem.Id, 1).FirstOrDefault(); p.DefaultPictureModel.Title = parentPItem.Name; p.DefaultPictureModel.ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize); lstParentProducts.Add(p); counter++; } } catModel.Products = lstParentProducts; ////get subcategories //var subcats = _categoryService.GetAllCategoriesByParentCategoryId(catModel.Id); //IList<CategoryModel.SubCategoryModel> lstSubcategories = new List<CategoryModel.SubCategoryModel>(); foreach (Category item in subcats) { CategoryModel.SubCategoryModel s = new CategoryModel.SubCategoryModel(); s.Id = item.Id; s.Name = item.Name; s.PictureModel = null; IList<int> categoryIds = new List<int>(); categoryIds.Add(item.Id); //get sub-subcategories var subsubcats = _categoryService.GetAllCategoriesByParentCategoryId(item.Id); foreach (Category subsubcatitem in subsubcats) { categoryIds.Add(subsubcatitem.Id); } //add subcategory products var products = _productService.SearchProducts(0, 8, categoryIds, 0, 0, 0, 0, null, false, null, null, null, 0, null, false, true, false, 0, null, ProductSortingEnum.NameAsc, false, null); IList<ProductOverviewModel> lstProducts = new List<ProductOverviewModel>(); //int parentCounter = 0; //foreach (Product pitem in products) //{ // foreach (ProductCategory categoryItem in pitem.ProductCategories) // { // //if (categoryItem.CategoryId == item.Id && categoryItem.IsFeaturedProduct == true) // if (categoryItem.CategoryId == item.Id && parentCounter < 8) // { // ProductOverviewModel p = new ProductOverviewModel(); // decimal convertedPrice = Math.Round(pitem.Price, 2); // p.ProductPrice.Price = convertedPrice.ToString(); // p.Id = pitem.Id; // p.Name = pitem.Name; // p.SeName = pitem.GetSeName(); // p.ShortDescription = pitem.ShortDescription; // p.ProductPrice.OldPrice = pitem.OldPrice.ToString(); // var picture = _pictureService.GetPicturesByProductId(pitem.Id, 1).FirstOrDefault(); // p.DefaultPictureModel.Title = pitem.Name; // p.DefaultPictureModel.ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize); // lstProducts.Add(p); // parentCounter++; // } // } //} var specproducts = PrepareProductOverviewModels(products, true, true, null, true).ToList(); //s.Products = lstProducts; s.Products = specproducts; lstSubcategories.Add(s); } catModel.SubCategories = lstSubcategories; return catModel; }) .ToList() ); //get featured products var report = _cacheManager.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, _storeContext.CurrentStore.Id), () => _orderReportService.BestSellersReport(storeId: _storeContext.CurrentStore.Id, pageSize: 8)); var featuredProducts = _productService.GetProductsByIds(report.Select(x => x.ProductId).ToArray()); var featuredProductsOverview = PrepareProductOverviewModels(featuredProducts, true, true, null, true).ToList(); var featuredCategoryModel = new CategoryModel(); featuredCategoryModel.Name = "Featured Products"; featuredCategoryModel.Id = -99999; featuredCategoryModel.Products = featuredProductsOverview; if (model.Count == 0) return Content(""); CategoryContainerModel categoryModel = new CategoryContainerModel(); categoryModel.Categories = model; categoryModel.FeaturedCategory = featuredCategoryModel; //p.SpecificationAttributeModels = this.PrepareProductSpecificationModel(_workContext, // _specificationAttributeService, // _cacheManager, // parentPItem); //return PartialView(model); return PartialView(categoryModel); }