public virtual async Task <CategoryNavigationModel> PrepareCategoryNavigationModel(int currentCategoryId, int currentProductId) { //get active category var activeCategoryId = 0; if (currentCategoryId > 0) { //category details page activeCategoryId = currentCategoryId; } else if (currentProductId > 0) { //product details page int productCategories = _categoryService.GetProductCategoriesByProductId(currentProductId); if (productCategories != null) { activeCategoryId = productCategories; } //if (productCategories.Any()) // activeCategoryId = productCategories[0].CategoryId; } var cachedCategoriesModel = await PrepareCategorySimpleModels(0); var model = new CategoryNavigationModel { CurrentCategoryId = activeCategoryId, Categories = cachedCategoriesModel }; return(model); }
public virtual CategoryNavigationModel PrepareCategoryNavigationModel(int currentCategoryId, int currentProductId) { //get active category int activeCategoryId = 0; if (currentCategoryId > 0) { //category details page activeCategoryId = currentCategoryId; } else if (currentProductId > 0) { //product details page var productCategories = _categoryService.GetProductCategoriesByProductId(currentProductId); if (productCategories.Any()) { activeCategoryId = productCategories[0].CategoryId; } } var cachedCategoriesModel = PrepareCategorySimpleModels(); var model = new CategoryNavigationModel { CurrentCategoryId = activeCategoryId, Categories = cachedCategoriesModel }; return(model); }
protected CategoryNavigationModel[] PrepareCategoryNavigationArray(int categoryId, IList <int> customerCategoreis) { var category = _categoryService.GetCategoryById(categoryId); int lavel = 1; while (category.ParentCategoryId != 0) { lavel++; category = _categoryService.GetCategoryById(category.ParentCategoryId); } var categories = new CategoryNavigationModel[lavel]; category = _categoryService.GetCategoryById(_categoryService.GetCategoryById(categoryId).ParentCategoryId); int prevCategory = categoryId; int lvl = 1; for (int i = lavel - 1; i > 0; i--) { categories[i] = new CategoryNavigationModel(); categories[i].CurrentCategoryId = prevCategory; categories[i].Categories = (List <CategoryNavigationModel.CategoryModel>)PrepareCategoryNavigationModel(category.Id, ref lvl, customerCategoreis); if (category.ParentCategoryId != 0) { prevCategory = category.Id; category = _categoryService.GetCategoryById(category.ParentCategoryId); } } lvl = 1; categories[0] = new CategoryNavigationModel(); categories[0].CurrentCategoryId = category == null ? categoryId : category.Id; categories[0].Categories = (List <CategoryNavigationModel.CategoryModel>)PrepareCategoryNavigationModel(0, ref lvl, customerCategoreis); return(categories); }
public ActionResult CategoryNavigation(int currentCategoryId, int currentItemId) { int activeCategoryId = 0; if (currentCategoryId > 0) { activeCategoryId = currentCategoryId; } else if (currentItemId > 0) { var itemCategories = _categoryService.GetItemCategoriesByItemId(currentItemId); if (itemCategories.Any()) { activeCategoryId = itemCategories[0].CategoryId; } } var categoryModels = PrepareCategorySimpleModels(0).ToList(); var model = new CategoryNavigationModel { CurrentCategoryId = activeCategoryId, Categories = categoryModels }; return(PartialView(model)); }
public ActionResult Test(string widgetArea, object additionalData) { var categoryNavigationModel = new CategoryNavigationModel(); int currentCategoryId = (int)additionalData.GetType().GetProperty("currentCategoryId").GetValue(additionalData, null);; int currentProductId = (int)additionalData.GetType().GetProperty("currentProductId").GetValue(additionalData, null); int currentVendorId = (int)additionalData.GetType().GetProperty("currentVendorId").GetValue(additionalData, null); //return View(categoryNavigationModel); //get active category int activeCategoryId = 0; if (currentCategoryId > 0) { //category details page activeCategoryId = currentCategoryId; } else if (currentProductId > 0) { //product details page var productCategories = _categoryService.GetProductCategoriesByProductId(currentProductId); if (productCategories.Count > 0) { activeCategoryId = productCategories[0].CategoryId; } } else if (currentVendorId > 0) { //IList<ProductCategory> vendorCategories = _categoryService.GetProductCategoriesByVendorId(currentVendorId); } string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_NAVIGATION_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var cachedModel = _cacheManager.Get(cacheKey, () => PrepareCategorySimpleModels(0).ToList()); var model = new CategoryNavigationModel { CurrentCategoryId = activeCategoryId, Categories = cachedModel }; return(View("~/Plugins/Misc.Vendor/Views/Test/Test.cshtml", model)); }
private async void Category_OnClick(object sender, EventArgs e) { var stackLayout = (StackLayout)sender; var selectedCategoryNavigation = (CategorySimpleModel)stackLayout.BindingContext; if (selectedCategoryNavigation.SubCategories.Any()) { var categoryNavigationModel = new CategoryNavigationModel() { Categories = selectedCategoryNavigation.SubCategories }; var categoryPage = new CategoryNavigationPage() { BindingContext = new CategoryNavigationViewModel() { Categories = categoryNavigationModel.Categories.ToObservableCollection(), Title = selectedCategoryNavigation.Name, } }; await Navigation.PushAsync(categoryPage); } else { var category = await ViewModel.GetCategoryByIdAsync(selectedCategoryNavigation.Id); var categoryPage = new CategoryPage() { BindingContext = new CategoryViewModel() { CategoryId = selectedCategoryNavigation.Id, GetProductsByCategoryId = true, Title = selectedCategoryNavigation.Name, Category = category } }; await Navigation.PushAsync(categoryPage); } }
/// <summary> /// Display product/service/product buying request/service buyinng request tabs in catalog tab on homepage /// </summary> /// <param name="productItemType">ProductItemTypeEnum product/service/productbuyingrequest/servicebuyingrequest </param> /// <returns></returns> public ActionResult ProductCatalogTab(int productItemType) { int lvl = 2; var customerCategories = GetCustomerCategoryIds(productItemType == (int)ProductItemTypeEnum.Product, _workContext.WorkingLanguage.Id, 0); var categories = PrepareCategoryNavigationModel(0, ref lvl, customerCategories).Where(x => x.SubCategories.Count > 0).ToList(); categories = categories.Take(2).ToList(); categories = categories.Select(x => { x.SubCategories = x.SubCategories.Take(5).ToList(); return(x); }).ToList(); var model = new CategoryNavigationModel() { ItemType = ProductItemTypeEnum.Product, Categories = categories, }; model.ItemType = (ProductItemTypeEnum)productItemType; return(View(model)); }
/// <summary> /// Prepare category navigation model /// </summary> /// <param name="currentCategoryId">Current category identifier</param> /// <param name="currentProductId">Current product identifier</param> /// <returns>Category navigation model</returns> public virtual CategoryNavigationModel PrepareCategoryNavigationModel(int currentCategoryId, int currentProductId) { //get active category var activeCategoryId = 0; if (currentCategoryId > 0) { //category details page activeCategoryId = currentCategoryId; } else if (currentProductId > 0) { } var cachedCategoriesModel = PrepareCategorySimpleModels(); var model = new CategoryNavigationModel { CurrentCategoryId = activeCategoryId, Categories = cachedCategoriesModel }; return(model); }
public ActionResult GetSubCategories(int categoryId, bool product) { var customerCategories = GetCustomerCategoryIds(product, _workContext.WorkingLanguage.Id, categoryId); var model = new CategoryNavigationModel(); bool subCategories = false; int lvl = 1; model.Categories = (List <CategoryNavigationModel.CategoryModel>)PrepareCategoryNavigationModel(categoryId, ref lvl, customerCategories); if (model.Categories.Count > 0) { subCategories = true; } var category = _categoryService.GetCategoryById(categoryId); int lavel = 1; while (category.ParentCategoryId != 0) { lavel++; category = _categoryService.GetCategoryById(category.ParentCategoryId); } model.CurrentCategoryId = lavel; string html; html = RenderPartialViewToString("_categoryEditor", model); return(Json(new { haveConversionImages = GetProductConversionImagesModels(categoryId).Count > 0, lavel = lavel, id = categoryId, subCategories = subCategories, htmlString = html, seName = _categoryService.GetCategoryById(categoryId).GetSeName(_workContext.WorkingLanguage.Id) })); }
private CategoryNavigationModel GetCategoryNavigationModel(int currentCategoryId, int currentProductId) { var customerRolesIds = _workContext.CurrentCustomer.CustomerRoles.Where(cr => cr.Active).Select(cr => cr.Id).ToList(); string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_NAVIGATION_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", customerRolesIds), _storeContext.CurrentStore.Id); var categories = _cacheManager.Get(cacheKey, () => { return PrepareCategoryNavigationModel(); }); var breadcrumb = GetCurrentCategoryPath(currentCategoryId, currentProductId); // resolve number of products if (_catalogSettings.ShowCategoryProductNumber) { var curId = breadcrumb.LastOrDefault(); var curNode = curId == 0 ? categories.Root : categories.SelectNode(x => x.Value.Id == curId); this.ResolveCategoryProductsCount(curNode); } var model = new CategoryNavigationModel { Root = categories, Path = breadcrumb, CurrentCategoryId = breadcrumb.LastOrDefault() }; return model; }