public ActionResult RatesList(GridCommand command)
        {
            var sbwModel = _shippingByTotalService.GetAllShippingByTotalRecords()
                           .Select(x =>
            {
                var m = new ShippingByTotalModel
                {
                    Id                       = x.Id,
                    StoreId                  = x.StoreId,
                    ShippingMethodId         = x.ShippingMethodId,
                    CountryId                = x.CountryId,
                    From                     = x.From,
                    To                       = x.To,
                    UsePercentage            = x.UsePercentage,
                    ShippingChargePercentage = x.ShippingChargePercentage,
                    ShippingChargeAmount     = x.ShippingChargeAmount,
                    BaseCharge               = x.BaseCharge,
                    MaxCharge                = x.MaxCharge
                };
                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 : "*";

                var c               = _countryService.GetCountryById(x.CountryId ?? 0);
                m.CountryName       = (c != null) ? c.Name : "*";
                var s               = _stateProvinceService.GetStateProvinceById(x.StateProvinceId ?? 0);
                m.StateProvinceName = (s != null) ? s.Name : "*";
                m.Zip               = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*";

                return(m);
            })
                           .ToList();
            var model = new GridModel <ShippingByTotalModel>
            {
                Data  = sbwModel,
                Total = sbwModel.Count
            };

            return(new JsonResult
            {
                Data = model
            });
        }
Ejemplo n.º 2
0
        [HttpPost]  //TODO: Determine how to add back AdminAntiForgery
        public IActionResult AddShippingRate(ShippingByTotalModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(Json(new { Result = false, Message = _localizationService.GetResource("Plugins.Shipping.ByTotal.ManageShippingSettings.AccessDenied") }));
            }

            var zipPostalCode = model.ZipPostalCode;

            if (zipPostalCode != null)
            {
                int zipMaxLength = ByTotalShippingComputationMethod.ZipPostalCodeMaxLength;
                zipPostalCode = zipPostalCode.Trim();
                if (zipPostalCode.Length > zipMaxLength)
                {
                    zipPostalCode = zipPostalCode.Substring(0, zipMaxLength);
                }
            }

            var shippingByTotalRecord = new ShippingByTotalRecord
            {
                ShippingMethodId = model.ShippingMethodId,
                StoreId          = model.StoreId,
                WarehouseId      = model.WarehouseId,
                CountryId        = model.CountryId,
                StateProvinceId  = model.StateProvinceId,
                ZipPostalCode    = zipPostalCode,
                DisplayOrder     = model.DisplayOrder,
                From             = model.From,
                To                       = model.To,
                UsePercentage            = model.UsePercentage,
                ShippingChargePercentage = (model.UsePercentage) ? model.ShippingChargePercentage : 0,
                ShippingChargeAmount     = (model.UsePercentage) ? 0 : model.ShippingChargeAmount
            };

            _shippingByTotalService.InsertShippingByTotalRecord(shippingByTotalRecord);

            return(Json(new { Result = true }));
        }
        public ActionResult RateUpdate(ShippingByTotalModel model, GridCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult {
                    Data = "error"
                });
            }

            var shippingByTotalRecord = _shippingByTotalService.GetShippingByTotalRecordById(model.Id);

            shippingByTotalRecord.Zip                      = model.Zip == "*" ? null : model.Zip;
            shippingByTotalRecord.From                     = model.From;
            shippingByTotalRecord.To                       = model.To;
            shippingByTotalRecord.UsePercentage            = model.UsePercentage;
            shippingByTotalRecord.ShippingChargeAmount     = model.ShippingChargeAmount;
            shippingByTotalRecord.ShippingChargePercentage = model.ShippingChargePercentage;
            shippingByTotalRecord.BaseCharge               = model.BaseCharge;
            shippingByTotalRecord.MaxCharge                = model.MaxCharge;
            _shippingByTotalService.UpdateShippingByTotalRecord(shippingByTotalRecord);

            return(RatesList(command));
        }
        public IActionResult RatesList(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedKendoGridJson());
            }

            var records  = _shippingByTotalService.GetAllShippingByTotalRecords(command.Page - 1, command.PageSize);
            var sbtModel = records.Select(x =>
            {
                var m = new ShippingByTotalModel
                {
                    Id                       = x.Id,
                    StoreId                  = x.StoreId,
                    WarehouseId              = x.WarehouseId,
                    ShippingMethodId         = x.ShippingMethodId,
                    CountryId                = x.CountryId,
                    DisplayOrder             = x.DisplayOrder,
                    From                     = x.From,
                    To                       = x.To,
                    UsePercentage            = x.UsePercentage,
                    ShippingChargePercentage = x.ShippingChargePercentage,
                    ShippingChargeAmount     = x.ShippingChargeAmount,
                };

                // 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 : "*";
                m.CountryId   = x.CountryId;

                // state/province
                var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId);
                m.StateProvinceName = (s != null) ? s.Name : "*";
                m.StateProvinceId   = x.StateProvinceId;

                // ZIP / postal code
                m.ZipPostalCode = (!String.IsNullOrEmpty(x.ZipPostalCode)) ? x.ZipPostalCode : "*";

                return(m);
            })
                           .ToList();
            var gridModel = new DataSourceResult
            {
                Data  = sbtModel,
                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 ShippingByTotalListModel();

            foreach (var sm in shippingMethods)
            {
                model.AvailableShippingMethods.Add(new SelectListItem()
                {
                    Text = sm.Name, Value = sm.Id.ToString()
                });
            }

            //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()
                });
            }

            //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.AvailableStates.Add(new SelectListItem() { Text = "*", Value = "0" });
            model.LimitMethodsToCreated    = _shippingByTotalSettings.LimitMethodsToCreated;
            model.SmallQuantityThreshold   = _shippingByTotalSettings.SmallQuantityThreshold;
            model.SmallQuantitySurcharge   = _shippingByTotalSettings.SmallQuantitySurcharge;
            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;

            model.Records = _shippingByTotalService.GetAllShippingByTotalRecords()
                            .Select(x =>
            {
                var m = new ShippingByTotalModel
                {
                    Id                       = x.Id,
                    StoreId                  = x.StoreId,
                    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,
                    BaseCharge               = x.BaseCharge,
                    MaxCharge                = x.MaxCharge
                };
                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 : "*";

                var c               = _countryService.GetCountryById(x.CountryId ?? 0);
                m.CountryName       = (c != null) ? c.Name : "*";
                var s               = _stateProvinceService.GetStateProvinceById(x.StateProvinceId ?? 0);
                m.StateProvinceName = (s != null) ? s.Name : "*";
                m.Zip               = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*";

                return(m);
            })
                            .ToList();

            return(View("SmartStore.Plugin.Shipping.ByTotal.Views.ShippingByTotal.Configure", model));
        }