Esempio n. 1
0
        public IActionResult RatesList(ConfigurationModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedDataTablesJson());
            }

            var records = _shippingByTotalService.GetAllShippingByTotalRecords(model.Page - 1, model.PageSize);

            var gridModel = new ShippingByTotalListModel().PrepareToGrid(model, records, () =>
            {
                return(records.Select(record =>
                {
                    var sbtModel = new ShippingByTotalModel
                    {
                        Id = record.Id,
                        StoreId = record.StoreId,
                        WarehouseId = record.WarehouseId,
                        ShippingMethodId = record.ShippingMethodId,
                        CountryId = record.CountryId,
                        DisplayOrder = record.DisplayOrder,
                        From = record.From,
                        To = record.To,
                        UsePercentage = record.UsePercentage,
                        ShippingChargePercentage = record.ShippingChargePercentage,
                        ShippingChargeAmount = record.ShippingChargeAmount,
                    };

                    // shipping method
                    var shippingMethod = _shippingService.GetShippingMethodById(record.ShippingMethodId);
                    sbtModel.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable";

                    // store
                    var store = _storeService.GetStoreById(record.StoreId);
                    sbtModel.StoreName = (store != null) ? store.Name : "*";

                    // warehouse
                    var warehouse = _shippingService.GetWarehouseById(record.WarehouseId);
                    sbtModel.WarehouseName = (warehouse != null) ? warehouse.Name : "*";

                    // country
                    var c = _countryService.GetCountryById(record.CountryId);
                    sbtModel.CountryName = (c != null) ? c.Name : "*";
                    sbtModel.CountryId = record.CountryId;

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

                    // ZIP / postal code
                    sbtModel.ZipPostalCode = (!string.IsNullOrEmpty(record.ZipPostalCode)) ? record.ZipPostalCode : "*";

                    return sbtModel;
                }));
            });

            return(Json(gridModel));
        }
        public ActionResult SaveGeneralSettings(ShippingByTotalListModel model)
        {
            //save settings
            _shippingByTotalSettings.LimitMethodsToCreated  = model.LimitMethodsToCreated;
            _shippingByTotalSettings.SmallQuantityThreshold = model.SmallQuantityThreshold;
            _shippingByTotalSettings.SmallQuantitySurcharge = model.SmallQuantitySurcharge;

            _settingService.SaveSetting(_shippingByTotalSettings);

            return(Json(new { Result = true }));
        }
        public IActionResult SaveGeneralSettings(ShippingByTotalListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(Json(new { Result = false, Message = _localizationService.GetResource("Plugins.Shipping.ByTotal.ManageShippingSettings.AccessDenied") }));
            }

            //save settings
            _shippingByTotalSettings.LimitMethodsToCreated = model.LimitMethodsToCreated;
            _settingService.SaveSetting(_shippingByTotalSettings);

            return(Json(new { Result = true, Message = _localizationService.GetResource("Plugins.Shipping.ByTotal.ManageShippingSettings.Saved") }));
        }
        public IActionResult AddShippingRate(ShippingByTotalListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(Json(new { Result = false, Message = _localizationService.GetResource("Plugins.Shipping.ByTotal.ManageShippingSettings.AccessDenied") }));
            }

            var zipPostalCode = model.AddZipPostalCode;

            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.AddShippingMethodId,
                StoreId          = model.AddStoreId,
                WarehouseId      = model.AddWarehouseId,
                CountryId        = model.AddCountryId,
                StateProvinceId  = model.AddStateProvinceId,
                ZipPostalCode    = zipPostalCode,
                DisplayOrder     = model.AddDisplayOrder,
                From             = model.AddFrom,
                To                       = model.AddTo,
                UsePercentage            = model.AddUsePercentage,
                ShippingChargePercentage = (model.AddUsePercentage) ? model.AddShippingChargePercentage : 0,
                ShippingChargeAmount     = (model.AddUsePercentage) ? 0 : model.AddShippingChargeAmount
            };

            _shippingByTotalService.InsertShippingByTotalRecord(shippingByTotalRecord);

            return(Json(new { Result = true }));
        }
        public ActionResult AddShippingRate(ShippingByTotalListModel model)
        {
            var shippingByTotalRecord = new ShippingByTotalRecord
            {
                StoreId          = model.AddStoreId,
                ShippingMethodId = model.AddShippingMethodId,
                CountryId        = model.AddCountryId,
                StateProvinceId  = model.AddStateProvinceId,
                Zip                      = model.AddZip,
                From                     = model.AddFrom,
                To                       = model.AddTo,
                UsePercentage            = model.AddUsePercentage,
                ShippingChargePercentage = (model.AddUsePercentage) ? model.AddShippingChargePercentage : 0,
                ShippingChargeAmount     = (model.AddUsePercentage) ? 0 : model.AddShippingChargeAmount,
                BaseCharge               = model.AddBaseCharge,
                MaxCharge                = model.AddMaxCharge
            };

            _shippingByTotalService.InsertShippingByTotalRecord(shippingByTotalRecord);

            return(Json(new { Result = true }));
        }
        public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedView());
            }

            var shippingMethods = _shippingService.GetAllShippingMethods();

            if (shippingMethods.Count == 0)
            {
                return(Content("No shipping methods can be loaded"));
            }

            var model = new ShippingByTotalListModel();

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

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

            // 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(showHidden: 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.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;

            return(View("~/Plugins/Shipping.ByTotal/Views/Configure.cshtml", model));
        }
        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));
        }