//add public ActionResult AddPopup() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return Content("Access denied"); var model = new ShippingByWeightModel(); model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; model.To = 1000000; var shippingMethods = _shippingService.GetAllShippingMethods(); if (shippingMethods.Count == 0) return Content("No shipping methods can be loaded"); //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" }); return View("Nop.Plugin.Shipping.ByWeight.Views.ShippingByWeight.AddPopup", model); }
public ActionResult Configure() { var shippingMethods = _shippingService.GetAllShippingMethods(); if (shippingMethods.Count == 0) return Content("No shipping methods can be loaded"); var model = new ShippingByWeightListModel(); foreach (var sm in shippingMethods) model.AvailableShippingMethods.Add(new SelectListItem() { Text = sm.Name, Value = sm.Id.ToString() }); 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() }); model.LimitMethodsToCreated = _shippingByWeightSettings.LimitMethodsToCreated; model.CalculatePerWeightUnit = _shippingByWeightSettings.CalculatePerWeightUnit; model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; model.Records = _shippingByWeightService.GetAll() .Select(x => { var m = new ShippingByWeightModel() { Id = x.Id, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, From = x.From, To = x.To, UsePercentage = x.UsePercentage, ShippingChargePercentage = x.ShippingChargePercentage, ShippingChargeAmount = x.ShippingChargeAmount, }; var shippingMethodId = _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethodId != null) ? shippingMethodId.Name : "Unavailable"; if (x.CountryId > 0) { var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; } else { m.CountryName = "*"; } return m; }) .ToList(); return View("Nop.Plugin.Shipping.ByWeight.Views.ShippingByWeight.Configure", model); }
public ActionResult RateUpdate(ShippingByWeightModel model, GridCommand command) { var sbw = _shippingByWeightService.GetById(model.Id); sbw.From = model.From; sbw.To = model.To; sbw.UsePercentage = model.UsePercentage; sbw.ShippingChargeAmount = model.ShippingChargeAmount; sbw.ShippingChargePercentage = model.ShippingChargePercentage; _shippingByWeightService.UpdateShippingByWeightRecord(sbw); return RatesList(command); }
public ActionResult RatesList(GridCommand command) { var sbwModel = _shippingByWeightService.GetAll() .Select(x => { var m = new ShippingByWeightModel() { Id = x.Id, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, From = x.From, To = x.To, UsePercentage = x.UsePercentage, ShippingChargePercentage = x.ShippingChargePercentage, ShippingChargeAmount = x.ShippingChargeAmount, }; var shippingMethodId = _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethodId != null) ? shippingMethodId.Name : "Unavailable"; if (x.CountryId > 0) { var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; } else { m.CountryName = "*"; } return m; }) .ToList(); var model = new GridModel<ShippingByWeightModel> { Data = sbwModel, Total = sbwModel.Count }; return new JsonResult { Data = model }; }
public ActionResult AddPopup(string btnId, string formId, ShippingByWeightModel model) { var sbw = new ShippingByWeightRecord() { CountryId = model.CountryId, StateProvinceId = model.StateProvinceId, Zip = model.Zip == "*" ? null : model.Zip, ShippingMethodId = model.ShippingMethodId, From = model.From, To = model.To, AdditionalFixedCost = model.AdditionalFixedCost, RatePerWeightUnit = model.RatePerWeightUnit, PercentageRateOfSubtotal = model.PercentageRateOfSubtotal, LowerWeightLimit = model.LowerWeightLimit }; _shippingByWeightService.InsertShippingByWeightRecord(sbw); ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View("Nop.Plugin.Shipping.ByWeight.Views.ShippingByWeight.AddPopup", model); }
public ActionResult RatesList(GridCommand command) { var records = _shippingByWeightService.GetAll(command.Page - 1, command.PageSize); var sbwModel = records.Select(x => { var m = new ShippingByWeightModel() { Id = x.Id, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, From = x.From, To = x.To, AdditionalFixedCost = x.AdditionalFixedCost, PercentageRateOfSubtotal = x.PercentageRateOfSubtotal, RatePerWeightUnit = x.RatePerWeightUnit, LowerWeightLimit = x.LowerWeightLimit, }; 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 : "*"; 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(); return m; }) .ToList(); var model = new GridModel<ShippingByWeightModel> { Data = sbwModel, Total = records.TotalCount }; return new JsonResult { Data = model }; }
public ActionResult EditPopup(string btnId, string formId, ShippingByWeightModel model) { var sbw = _shippingByWeightService.GetById(model.Id); if (sbw == null) //No record found with the specified id return RedirectToAction("Configure"); sbw.CountryId = model.CountryId; sbw.StateProvinceId = model.StateProvinceId; sbw.Zip = model.Zip == "*" ? null : model.Zip; sbw.ShippingMethodId = model.ShippingMethodId; sbw.From = model.From; sbw.To = model.To; sbw.AdditionalFixedCost = model.AdditionalFixedCost; sbw.RatePerWeightUnit = model.RatePerWeightUnit; sbw.PercentageRateOfSubtotal = model.PercentageRateOfSubtotal; sbw.LowerWeightLimit = model.LowerWeightLimit; _shippingByWeightService.UpdateShippingByWeightRecord(sbw); ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View("Nop.Plugin.Shipping.ByWeight.Views.ShippingByWeight.EditPopup", model); }
//edit public ActionResult EditPopup(int id) { var sbw = _shippingByWeightService.GetById(id); if (sbw == null) //No record found with the specified id return RedirectToAction("Configure"); var model = new ShippingByWeightModel() { Id = sbw.Id, CountryId = sbw.CountryId, StateProvinceId = sbw.StateProvinceId, Zip = sbw.Zip, ShippingMethodId = sbw.ShippingMethodId, From = sbw.From, To = sbw.To, AdditionalFixedCost = sbw.AdditionalFixedCost, PercentageRateOfSubtotal = sbw.PercentageRateOfSubtotal, RatePerWeightUnit = sbw.RatePerWeightUnit, LowerWeightLimit = sbw.LowerWeightLimit, PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode, BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name }; var shippingMethods = _shippingService.GetAllShippingMethods(); if (shippingMethods.Count == 0) return Content("No shipping methods can be loaded"); var selectedShippingMethod = _shippingService.GetShippingMethodById(sbw.ShippingMethodId); var selectedCountry = _countryService.GetCountryById(sbw.CountryId); var selectedState = _stateProvinceService.GetStateProvinceById(sbw.StateProvinceId); //shipping methods foreach (var sm in shippingMethods) model.AvailableShippingMethods.Add(new SelectListItem() { Text = sm.Name, Value = sm.Id.ToString(), Selected = (selectedShippingMethod != null && sm.Id == selectedShippingMethod.Id) }); //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(), Selected = (selectedCountry != null && c.Id == selectedCountry.Id) }); //states var states = selectedCountry != null ? _stateProvinceService.GetStateProvincesByCountryId(selectedCountry.Id, true).ToList() : new List<StateProvince>(); model.AvailableStates.Add(new SelectListItem() { Text = "*", Value = "0" }); foreach (var s in states) model.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (selectedState != null && s.Id == selectedState.Id) }); return View("Nop.Plugin.Shipping.ByWeight.Views.ShippingByWeight.EditPopup", model); }
public ActionResult RatesList(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, 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 : "*"; //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.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(); return m; }) .ToList(); var gridModel = new DataSourceResult { Data = sbwModel, Total = records.TotalCount }; return Json(gridModel); }
public ActionResult EditPopup(string btnId, string formId, ShippingByWeightModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return Content("Access denied"); var sbw = _shippingByWeightService.GetById(model.Id); if (sbw == null) //No record found with the specified id return RedirectToAction("Configure"); sbw.StoreId = model.StoreId; sbw.CountryId = model.CountryId; sbw.StateProvinceId = model.StateProvinceId; sbw.Zip = model.Zip == "*" ? null : model.Zip; sbw.ShippingMethodId = model.ShippingMethodId; sbw.From = model.From; sbw.To = model.To; sbw.AdditionalFixedCost = model.AdditionalFixedCost; sbw.RatePerWeightUnit = model.RatePerWeightUnit; sbw.PercentageRateOfSubtotal = model.PercentageRateOfSubtotal; sbw.LowerWeightLimit = model.LowerWeightLimit; _shippingByWeightService.UpdateShippingByWeightRecord(sbw); ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View("~/Plugins/Shipping.ByWeight/Views/ShippingByWeight/EditPopup.cshtml", model); }
public ActionResult AddPopup(string btnId, string formId, ShippingByWeightModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return Content("Access denied"); var sbw = new ShippingByWeightRecord() { StoreId = model.StoreId, CountryId = model.CountryId, StateProvinceId = model.StateProvinceId, Zip = model.Zip == "*" ? null : model.Zip, ShippingMethodId = model.ShippingMethodId, From = model.From, To = model.To, AdditionalFixedCost = model.AdditionalFixedCost, RatePerWeightUnit = model.RatePerWeightUnit, PercentageRateOfSubtotal = model.PercentageRateOfSubtotal, LowerWeightLimit = model.LowerWeightLimit }; _shippingByWeightService.InsertShippingByWeightRecord(sbw); ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View("~/Plugins/Shipping.ByWeight/Views/ShippingByWeight/AddPopup.cshtml", model); }
//edit public ActionResult EditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return Content("Access denied"); var sbw = _shippingByWeightService.GetById(id); if (sbw == null) //No record found with the specified id return RedirectToAction("Configure"); var model = new ShippingByWeightModel { Id = sbw.Id, StoreId = sbw.StoreId, WarehouseId = sbw.WarehouseId, CountryId = sbw.CountryId, StateProvinceId = sbw.StateProvinceId, Zip = sbw.Zip, ShippingMethodId = sbw.ShippingMethodId, From = sbw.From, To = sbw.To, AdditionalFixedCost = sbw.AdditionalFixedCost, PercentageRateOfSubtotal = sbw.PercentageRateOfSubtotal, RatePerWeightUnit = sbw.RatePerWeightUnit, LowerWeightLimit = sbw.LowerWeightLimit, PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode, BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name }; var shippingMethods = _shippingService.GetAllShippingMethods(); if (!shippingMethods.Any()) return Content("No shipping methods can be loaded"); var selectedStore = _storeService.GetStoreById(sbw.StoreId); var selectedWarehouse = _shippingService.GetWarehouseById(sbw.WarehouseId); var selectedShippingMethod = _shippingService.GetShippingMethodById(sbw.ShippingMethodId); var selectedCountry = _countryService.GetCountryById(sbw.CountryId); var selectedState = _stateProvinceService.GetStateProvinceById(sbw.StateProvinceId); //stores model.AvailableStores.Add(new SelectListItem { Text = "*", Value = "0" }); foreach (var store in _storeService.GetAllStores()) model.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = (selectedStore != null && store.Id == selectedStore.Id) }); //warehouses model.AvailableWarehouses.Add(new SelectListItem { Text = "*", Value = "0" }); foreach (var warehouse in _shippingService.GetAllWarehouses()) model.AvailableWarehouses.Add(new SelectListItem { Text = warehouse.Name, Value = warehouse.Id.ToString(), Selected = (selectedWarehouse != null && warehouse.Id == selectedWarehouse.Id) }); //shipping methods foreach (var sm in shippingMethods) model.AvailableShippingMethods.Add(new SelectListItem { Text = sm.Name, Value = sm.Id.ToString(), Selected = (selectedShippingMethod != null && sm.Id == selectedShippingMethod.Id) }); //countries model.AvailableCountries.Add(new SelectListItem { Text = "*", Value = "0" }); var countries = _countryService.GetAllCountries(showHidden: true); foreach (var c in countries) model.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString(), Selected = (selectedCountry != null && c.Id == selectedCountry.Id) }); //states var states = selectedCountry != null ? _stateProvinceService.GetStateProvincesByCountryId(selectedCountry.Id, showHidden: true).ToList() : new List<StateProvince>(); model.AvailableStates.Add(new SelectListItem { Text = "*", Value = "0" }); foreach (var s in states) model.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (selectedState != null && s.Id == selectedState.Id) }); return View("~/Plugins/Shipping.ByWeight/Views/ShippingByWeight/EditPopup.cshtml", model); }
public ActionResult RatesList(GridCommand command) { var sbwModel = _shippingByWeightService.GetAll() .Select(x => { var m = new ShippingByWeightModel() { Id = x.Id, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, 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(); var model = new GridModel<ShippingByWeightModel> { Data = sbwModel, Total = sbwModel.Count }; return new JsonResult { Data = model }; }
public ActionResult RateUpdate(ShippingByWeightModel model, GridCommand command) { if (!ModelState.IsValid) { return new JsonResult { Data = "error" }; } var sbw = _shippingByWeightService.GetById(model.Id); sbw.From = model.From; sbw.To = model.To; sbw.UsePercentage = model.UsePercentage; sbw.ShippingChargeAmount = model.ShippingChargeAmount; sbw.ShippingChargePercentage = model.ShippingChargePercentage; _shippingByWeightService.UpdateShippingByWeightRecord(sbw); return RatesList(command); }