/// <summary> /// Prepare product search model to add to the manufacturer /// </summary> /// <param name="searchModel">Product search model to add to the manufacturer</param> /// <returns>Product search model to add to the manufacturer</returns> public virtual async Task <AddProductToManufacturerSearchModel> PrepareAddProductToManufacturerSearchModelAsync(AddProductToManufacturerSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare available categories await _baseAdminModelFactory.PrepareCategoriesAsync(searchModel.AvailableCategories); //prepare available manufacturers await _baseAdminModelFactory.PrepareManufacturersAsync(searchModel.AvailableManufacturers); //prepare available stores await _baseAdminModelFactory.PrepareStoresAsync(searchModel.AvailableStores); //prepare available vendors await _baseAdminModelFactory.PrepareVendorsAsync(searchModel.AvailableVendors); //prepare available product types await _baseAdminModelFactory.PrepareProductTypesAsync(searchModel.AvailableProductTypes); //prepare page parameters searchModel.SetPopupGridPageSize(); return(searchModel); }
/// <summary> /// Prepare customer role product search model /// </summary> /// <param name="searchModel">Customer role product search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the customer role product search model /// </returns> public virtual async Task <CustomerRoleProductSearchModel> PrepareCustomerRoleProductSearchModelAsync(CustomerRoleProductSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //a vendor should have access only to his products searchModel.IsLoggedInAsVendor = await _workContext.GetCurrentVendorAsync() != null; //prepare available categories await _baseAdminModelFactory.PrepareCategoriesAsync(searchModel.AvailableCategories); //prepare available manufacturers await _baseAdminModelFactory.PrepareManufacturersAsync(searchModel.AvailableManufacturers); //prepare available stores await _baseAdminModelFactory.PrepareStoresAsync(searchModel.AvailableStores); //prepare available vendors await _baseAdminModelFactory.PrepareVendorsAsync(searchModel.AvailableVendors); //prepare available product types await _baseAdminModelFactory.PrepareProductTypesAsync(searchModel.AvailableProductTypes); //prepare page parameters searchModel.SetPopupGridPageSize(); return(searchModel); }
/// <summary> /// Prepare sales summary search model /// </summary> /// <param name="searchModel">Sales summary search model</param> /// <returns>Sales summary search model</returns> public virtual async Task <SalesSummarySearchModel> PrepareSalesSummarySearchModelAsync(SalesSummarySearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } searchModel.IsLoggedInAsVendor = await _workContext.GetCurrentVendorAsync() != null; //prepare available stores await _baseAdminModelFactory.PrepareStoresAsync(searchModel.AvailableStores); //prepare available order statuses await _baseAdminModelFactory.PrepareOrderStatusesAsync(searchModel.AvailableOrderStatuses); //prepare available payment statuses await _baseAdminModelFactory.PreparePaymentStatusesAsync(searchModel.AvailablePaymentStatuses); //prepare available categories await _baseAdminModelFactory.PrepareCategoriesAsync(searchModel.AvailableCategories); //prepare available manufacturers await _baseAdminModelFactory.PrepareManufacturersAsync(searchModel.AvailableManufacturers); //prepare available billing countries searchModel.AvailableCountries = (await _countryService.GetAllCountriesForBillingAsync(showHidden: true)) .Select(country => new SelectListItem { Text = country.Name, Value = country.Id.ToString() }).ToList(); searchModel.AvailableCountries.Insert(0, new SelectListItem { Text = await _localizationService.GetResourceAsync("Admin.Common.All"), Value = "0" }); //prepare "group by" filter searchModel.GroupByOptions = (await GroupByOptions.Day.ToSelectListAsync()).ToList(); //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare category model /// </summary> /// <param name="model">Category model</param> /// <param name="category">Category</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the category model /// </returns> public virtual async Task <CategoryModel> PrepareCategoryModelAsync(CategoryModel model, Category category, bool excludeProperties = false) { Func <CategoryLocalizedModel, int, Task> localizedModelConfiguration = null; if (category != null) { //fill in model values from the entity if (model == null) { model = category.ToModel <CategoryModel>(); model.SeName = await _urlRecordService.GetSeNameAsync(category, 0, true, false); } //prepare nested search model PrepareCategoryProductSearchModel(model.CategoryProductSearchModel, category); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(category, entity => entity.Name, languageId, false, false); locale.Description = await _localizationService.GetLocalizedAsync(category, entity => entity.Description, languageId, false, false); locale.MetaKeywords = await _localizationService.GetLocalizedAsync(category, entity => entity.MetaKeywords, languageId, false, false); locale.MetaDescription = await _localizationService.GetLocalizedAsync(category, entity => entity.MetaDescription, languageId, false, false); locale.MetaTitle = await _localizationService.GetLocalizedAsync(category, entity => entity.MetaTitle, languageId, false, false); locale.SeName = await _urlRecordService.GetSeNameAsync(category, languageId, false, false); }; } //set default values for the new model if (category == null) { model.PageSize = _catalogSettings.DefaultCategoryPageSize; model.PageSizeOptions = _catalogSettings.DefaultCategoryPageSizeOptions; model.Published = true; model.IncludeInTopMenu = true; model.AllowCustomersToSelectPageSize = true; model.PriceRangeFiltering = true; model.ManuallyPriceRange = true; model.PriceFrom = NopCatalogDefaults.DefaultPriceRangeFrom; model.PriceTo = NopCatalogDefaults.DefaultPriceRangeTo; } model.PrimaryStoreCurrencyCode = (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId)).CurrencyCode; //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } //prepare available category templates await _baseAdminModelFactory.PrepareCategoryTemplatesAsync(model.AvailableCategoryTemplates, false); //prepare available parent categories await _baseAdminModelFactory.PrepareCategoriesAsync(model.AvailableCategories, defaultItemText : await _localizationService.GetResourceAsync("Admin.Catalog.Categories.Fields.Parent.None")); //prepare model discounts var availableDiscounts = await _discountService.GetAllDiscountsAsync(DiscountType.AssignedToCategories, showHidden : true); await _discountSupportedModelFactory.PrepareModelDiscountsAsync(model, category, availableDiscounts, excludeProperties); //prepare model customer roles await _aclSupportedModelFactory.PrepareModelCustomerRolesAsync(model, category, excludeProperties); //prepare model stores await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, category, excludeProperties); return(model); }