public CategoryModel() { if (PageSize < 1) { PageSize = 5; } Locales = new List <CategoryLocalizedModel>(); AvailableCategoryTemplates = new List <SelectListItem>(); AvailableCategories = new List <SelectListItem>(); AvailableDiscounts = new List <SelectListItem>(); SelectedDiscountIds = new List <int>(); SelectedCustomerRoleIds = new List <int>(); AvailableCustomerRoles = new List <SelectListItem>(); SelectedStoreIds = new List <int>(); AvailableStores = new List <SelectListItem>(); CategoryProductSearchModel = new CategoryProductSearchModel(); // custom code start TierPriceSearchModel = new CustomTierPriceSearchModel(); // custom code end }
public virtual IActionResult TierPriceList(CustomTierPriceSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) { return(AccessDeniedDataTablesJson()); } //try to get a category with the specified id var category = _categoryService.GetCategoryById(searchModel.CategoryId) ?? throw new ArgumentException("No category found with the specified id"); //a vendor should have access only to his category //prepare model var model = _tirePriceModelFactory.PrepareTierPriceListModel(searchModel, category); return(Json(model)); }
// custom code start /// <summary> /// Prepare tier price search model /// </summary> /// <param name="searchModel">Tier price search model</param> /// <param name="category">Category</param> /// <returns>Tier price search model</returns> protected virtual CustomTierPriceSearchModel PrepareTierPriceSearchModel(CustomTierPriceSearchModel searchModel, Category category) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (category == null) { throw new ArgumentNullException(nameof(category)); } searchModel.CategoryId = category.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare paged tier price list model /// </summary> /// <param name="searchModel">Tier price search model</param> /// <param name="product">Product</param> /// <returns>Tier price list model</returns> public virtual TierPriceListModel PrepareTierPriceListModel(CustomTierPriceSearchModel searchModel, Category category) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (category == null) { throw new ArgumentNullException(nameof(category)); } //get tier prices var tierPrices = _tierpriceService.GetTierPricesByCategory(category.Id) .OrderBy(price => price.StoreId).ThenBy(price => price.Quantity).ThenBy(price => price.CustomerRoleId) .ToList().ToPagedList(searchModel); //prepare grid model var model = new TierPriceListModel().PrepareToGrid(searchModel, tierPrices, () => { return(tierPrices.Select(price => { //fill in model values from the entity var tierPriceModel = price.ToModel <TierPriceModel>(); //fill in additional values (not existing in the entity) tierPriceModel.Store = price.StoreId > 0 ? (_storeService.GetStoreById(price.StoreId)?.Name ?? "Deleted") : _localizationService.GetResource("Admin.Catalog.Products.TierPrices.Fields.Store.All"); tierPriceModel.CustomerRoleId = price.CustomerRoleId ?? 0; tierPriceModel.CustomerRole = price.CustomerRoleId.HasValue ? _customerService.GetCustomerRoleById(price.CustomerRoleId.Value).Name : _localizationService.GetResource("Admin.Catalog.Products.TierPrices.Fields.CustomerRole.All"); return tierPriceModel; })); }); return(model); }