public async Task <IActionResult> RatesList(DataSourceRequest command) { var records = await _shippingByWeightService.GetAll(command.Page - 1, command.PageSize); var sbwModel = new List <ShippingByWeightModel>(); foreach (var x in records) { var m = new ShippingByWeightModel { Id = x.Id, StoreId = x.StoreId, WarehouseId = x.WarehouseId, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, From = x.From, To = x.To, AdditionalFixedCost = x.AdditionalFixedCost, PercentageRateOfSubtotal = x.PercentageRateOfSubtotal, RatePerWeightUnit = x.RatePerWeightUnit, LowerWeightLimit = x.LowerWeightLimit, }; //shipping method var shippingMethod = await _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable"; //store var store = await _storeService.GetStoreById(x.StoreId); m.StoreName = (store != null) ? store.Shortcut : "*"; //warehouse var warehouse = await _shippingService.GetWarehouseById(x.WarehouseId); m.WarehouseName = (warehouse != null) ? warehouse.Name : "*"; //country var c = await _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "*"; //state var s = await _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; //zip m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; var htmlSb = new StringBuilder("<div>"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.From"), m.From); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.To"), m.To); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.AdditionalFixedCost"), m.AdditionalFixedCost); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.RatePerWeightUnit"), m.RatePerWeightUnit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.LowerWeightLimit"), m.LowerWeightLimit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.PercentageRateOfSubtotal"), m.PercentageRateOfSubtotal); htmlSb.Append("</div>"); m.DataHtml = htmlSb.ToString(); sbwModel.Add(m); } var gridModel = new DataSourceResult { Data = sbwModel, Total = records.TotalCount }; return(Json(gridModel)); }
public ActionResult RateByWeightList(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(Content("Access denied")); } var records = _shippingByWeightService.GetAll(command.Page - 1, command.PageSize); var sbwModel = records.Select(x => { var m = new ShippingByWeightModel { Id = x.Id, StoreId = x.StoreId, WarehouseId = x.WarehouseId, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, From = x.From, To = x.To, AdditionalFixedCost = x.AdditionalFixedCost, PercentageRateOfSubtotal = x.PercentageRateOfSubtotal, RatePerWeightUnit = x.RatePerWeightUnit, LowerWeightLimit = x.LowerWeightLimit, }; //shipping method var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable"; //store var store = _storeService.GetStoreById(x.StoreId); m.StoreName = (store != null) ? store.Name : "*"; //warehouse var warehouse = _shippingService.GetWarehouseById(x.WarehouseId); m.WarehouseName = (warehouse != null) ? warehouse.Name : "*"; //country var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "*"; //state var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; //zip m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; var htmlSb = new StringBuilder("<div>"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.From"), m.From); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.To"), m.To); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.AdditionalFixedCost"), m.AdditionalFixedCost); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.RatePerWeightUnit"), m.RatePerWeightUnit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.LowerWeightLimit"), m.LowerWeightLimit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.PercentageRateOfSubtotal"), m.PercentageRateOfSubtotal); htmlSb.Append("</div>"); m.DataHtml = htmlSb.ToString(); return(m); }) .ToList(); var gridModel = new DataSourceResult { Data = sbwModel, Total = records.TotalCount }; return(Json(gridModel)); }
public IActionResult RateByWeightList(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedKendoGridJson()); } var records = _shippingByWeightService.GetAll(command.Page - 1, command.PageSize); var sbwModel = records.Select(record => { var model = new ShippingByWeightModel { Id = record.Id, StoreId = record.StoreId, StoreName = _storeService.GetStoreById(record.StoreId)?.Name ?? "*", WarehouseId = record.WarehouseId, WarehouseName = _shippingService.GetWarehouseById(record.WarehouseId)?.Name ?? "*", ShippingMethodId = record.ShippingMethodId, ShippingMethodName = _shippingService.GetShippingMethodById(record.ShippingMethodId)?.Name ?? "Unavailable", CountryId = record.CountryId, CountryName = _countryService.GetCountryById(record.CountryId)?.Name ?? "*", CategoryId = record.CategoryId, //amal 25/10/2018 CategoryName = _categoryService.GetCategoryById(record.CategoryId)?.Name ?? "*", //amal 25/10/2018 StateProvinceId = record.StateProvinceId, StateProvinceName = _stateProvinceService.GetStateProvinceById(record.StateProvinceId)?.Name ?? "*", From = record.From, To = record.To, AdditionalFixedCost = record.AdditionalFixedCost, PercentageRateOfSubtotal = record.PercentageRateOfSubtotal, RatePerWeightUnit = record.RatePerWeightUnit, LowerWeightLimit = record.LowerWeightLimit, Zip = !string.IsNullOrEmpty(record.Zip) ? record.Zip : "*" }; var htmlSb = new StringBuilder("<div>"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.From"), model.From); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.To"), model.To); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.AdditionalFixedCost"), model.AdditionalFixedCost); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.RatePerWeightUnit"), model.RatePerWeightUnit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.LowerWeightLimit"), model.LowerWeightLimit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.PercentageRateOfSubtotal"), model.PercentageRateOfSubtotal); htmlSb.Append("</div>"); model.DataHtml = htmlSb.ToString(); return(model); }).ToList(); var gridModel = new DataSourceResult { Data = sbwModel, Total = records.TotalCount }; return(Json(gridModel)); }
public ActionResult Configure() { var shippingMethods = _shippingService.GetAllShippingMethods(); if (shippingMethods.Count == 0) { return(Content("No shipping methods can be loaded")); } var model = new ShippingByWeightListModel(); //shipping methods foreach (var sm in shippingMethods) { model.AvailableShippingMethods.Add(new SelectListItem() { Text = sm.Name, Value = sm.Id.ToString() }); } //countries model.AvailableCountries.Add(new SelectListItem() { Text = "*", Value = "0" }); var countries = _countryService.GetAllCountries(true); foreach (var c in countries) { model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() }); } //states model.AvailableStates.Add(new SelectListItem() { Text = "*", Value = "0" }); //other settings model.LimitMethodsToCreated = _shippingByWeightSettings.LimitMethodsToCreated; model.CalculatePerWeightUnit = _shippingByWeightSettings.CalculatePerWeightUnit; model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; //rates model.Records = _shippingByWeightService.GetAll() .Select(x => { var m = new ShippingByWeightModel() { Id = x.Id, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = x.Zip, From = x.From, To = x.To, UsePercentage = x.UsePercentage, ShippingChargePercentage = x.ShippingChargePercentage, ShippingChargeAmount = x.ShippingChargeAmount, }; var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable"; var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "*"; var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; return(m); }) .ToList(); return(View("Nop.Plugin.Shipping.ByWeight.Views.ShippingByWeight.Configure", model)); }