Exemplo n.º 1
0
        //[Test]
        public void AllStoreSettings()
        {
            var settingService = MerchelloContext.Current.Services.StoreSettingService;
            var settings = settingService.GetAll();
            var settingDisplay = new SettingDisplay();

            Console.WriteLine(JsonConvert.SerializeObject(settingDisplay.ToStoreSettingDisplay(settings)));
        }
Exemplo n.º 2
0
        internal static IEnumerable <IStoreSetting> ToStoreSetting(this SettingDisplay settingDisplay, IEnumerable <IStoreSetting> destination)
        {
            foreach (var setting in destination)
            {
                switch (setting.Name)
                {
                case "currencyCode":
                    setting.Value = settingDisplay.CurrencyCode;
                    break;

                case "nextOrderNumber":
                    setting.Value = settingDisplay.NextOrderNumber.ToString();
                    break;

                case "nextInvoiceNumber":
                    setting.Value = settingDisplay.NextInvoiceNumber.ToString();
                    break;

                case "nextShipmentNumber":
                    setting.Value = settingDisplay.NextShipmentNumber.ToString();
                    break;

                case "dateFormat":
                    setting.Value = settingDisplay.DateFormat;
                    break;

                case "timeFormat":
                    setting.Value = settingDisplay.TimeFormat;
                    break;

                case "unitSystem":
                    setting.Value = settingDisplay.UnitSystem;
                    break;

                case "globalShippable":
                    setting.Value = settingDisplay.GlobalShippable.ToString();
                    break;

                case "globalTaxable":
                    setting.Value = settingDisplay.GlobalTaxable.ToString();
                    break;

                case "globalTrackInventory":
                    setting.Value = settingDisplay.GlobalTrackInventory.ToString();
                    break;

                case "globalShippingIsTaxable":
                    setting.Value = settingDisplay.GlobalShippingIsTaxable.ToString();
                    break;

                default:
                    setting.Value = string.Empty;
                    break;
                }
            }
            return(destination);
        }
Exemplo n.º 3
0
        public void Can_Build_StoreSettingsDisplay_From_StoreSettings()
        {
            var expectedSettings = StoreSettingService.GetAll();
            var settingDisplay = new SettingDisplay();

            var actualSettings = settingDisplay.ToStoreSettingDisplay(expectedSettings);

            Assert.AreEqual(expectedSettings.First(x => x.Key == _currencyCodeKey).Value.ToLower().ToLower(), actualSettings.currencyCode.ToString().ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _nextInvoiceNumberKey).Value.ToLower(), actualSettings.nextInvoiceNumber.ToString().ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _nextOrderNumberkey).Value.ToLower(), actualSettings.nextOrderNumber.ToString().ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _dateFormatKey).Value.ToLower(), actualSettings.dateFormat.ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _timeFormatKey).Value.ToLower(), actualSettings.timeFormat.ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _globalShippableKey).Value.ToLower(), actualSettings.globalShippable.ToString().ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _globalShippingIsTaxableKey).Value.ToLower(), actualSettings.globalShippingIsTaxable.ToString().ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _globalTaxableKey).Value.ToLower(), actualSettings.globalTaxable.ToString().ToLower());
            Assert.AreEqual(expectedSettings.First(x => x.Key == _globalTrackInventoryKey).Value.ToLower(), actualSettings.globalTrackInventory.ToString().ToLower());
        }
Exemplo n.º 4
0
        public HttpResponseMessage PutSettings(SettingDisplay setting)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                IEnumerable<IStoreSetting> merchSetting = setting.ToStoreSetting(_storeSettingService.GetAll());
                foreach(var s in merchSetting)
                {
                    _storeSettingService.Save(s);
                }
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, String.Format("{0}", ex.Message));
            }

            return response;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the nextInvoiceNumber and nextOrderNumber
        /// </summary>
        /// <returns>Next Invoice Number and Next Order Number</returns>
        public SettingDisplay GetInvoiceAndOrderNumbers()
        {
            var settingDisplay = new SettingDisplay
            {
                nextInvoiceNumber = _storeSettingService.GetNextInvoiceNumber(),
                nextOrderNumber = _storeSettingService.GetNextOrderNumber()
            };

            return settingDisplay;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns Product by id (key) 
        /// GET /umbraco/Merchello/SettingsApi/GetAllSettings
        /// </summary>
        public SettingDisplay GetAllSettings()
        {
            var settings = _storeSettingService.GetAll();
            var settingDisplay = new SettingDisplay();

            if (settings == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return settingDisplay.ToStoreSettingDisplay(settings);
        }
Exemplo n.º 7
0
        internal static SettingDisplay ToStoreSettingDisplay(this SettingDisplay settingDisplay, IEnumerable <IStoreSetting> storeSettings)
        {
            int  intValue;
            bool boolValue;

            foreach (var setting in storeSettings)
            {
                switch (setting.Name)
                {
                case "currencyCode":
                    settingDisplay.currencyCode = setting.Value;
                    break;

                case "nextOrderNumber":
                    if (!int.TryParse(setting.Value, out intValue))
                    {
                        intValue = 0;
                    }
                    settingDisplay.nextOrderNumber = intValue;
                    break;

                case "nextInvoiceNumber":
                    if (!int.TryParse(setting.Value, out intValue))
                    {
                        intValue = 0;
                    }
                    settingDisplay.nextInvoiceNumber = intValue;
                    break;

                case "dateFormat":
                    settingDisplay.dateFormat = setting.Value;
                    break;

                case "timeFormat":
                    settingDisplay.timeFormat = setting.Value;
                    break;

                case "globalShippable":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.globalShippable = boolValue;
                    break;

                case "globalTaxable":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.globalTaxable = boolValue;
                    break;

                case "globalTrackInventory":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.globalTrackInventory = boolValue;
                    break;

                case "globalShippingIsTaxable":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.globalShippingIsTaxable = boolValue;
                    break;

                default:
                    setting.Value = string.Empty;
                    break;
                }
            }
            return(settingDisplay);
        }
Exemplo n.º 8
0
        public void Can_Build_StoreSettings_From_StoreSettingsDisplay()
        {
            var expectedSettings = new SettingDisplay()
            {
                currencyCode = "USD",
                dateFormat =  "mm-dd-yyyy",
                globalShippable = true,
                globalShippingIsTaxable = true,
                globalTaxable = true,
                globalTrackInventory = true,
                nextInvoiceNumber = 2,
                nextOrderNumber = 2,
                timeFormat = "am-pm"
            };

            IEnumerable<IStoreSetting> actualSettings = new List<IStoreSetting>();
            actualSettings = expectedSettings.ToStoreSetting();

            Assert.AreEqual(expectedSettings.currencyCode.ToLower(), actualSettings.First(x => x.Key == _currencyCodeKey).Value.ToLower().ToLower());
            Assert.AreEqual(expectedSettings.dateFormat.ToLower(), actualSettings.First(x => x.Key == _dateFormatKey).Value.ToLower());
            Assert.AreEqual(expectedSettings.globalShippable.ToString().ToLower(), actualSettings.First(x => x.Key == _globalShippableKey).Value.ToLower());
            Assert.AreEqual(expectedSettings.globalShippingIsTaxable.ToString().ToLower(), actualSettings.First(x => x.Key == _globalShippingIsTaxableKey).Value.ToLower());
            Assert.AreEqual(expectedSettings.globalTaxable.ToString().ToLower(), actualSettings.First(x => x.Key == _globalTaxableKey).Value.ToLower());
            Assert.AreEqual(expectedSettings.globalTrackInventory.ToString().ToLower(), actualSettings.First(x => x.Key == _globalTrackInventoryKey).Value.ToLower());
            Assert.AreEqual(expectedSettings.nextInvoiceNumber.ToString().ToLower(), actualSettings.First(x => x.Key == _nextInvoiceNumberKey).Value.ToLower());
            Assert.AreEqual(expectedSettings.nextOrderNumber.ToString().ToLower(), actualSettings.First(x => x.Key == _nextOrderNumberkey).Value.ToLower());
            Assert.AreEqual(expectedSettings.timeFormat.ToLower(), actualSettings.First(x => x.Key == _timeFormatKey).Value.ToLower());
        }
Exemplo n.º 9
0
        internal static SettingDisplay ToStoreSettingDisplay(this SettingDisplay settingDisplay, IEnumerable <IStoreSetting> storeSettings)
        {
            int  intValue;
            bool boolValue;

            foreach (var setting in storeSettings)
            {
                switch (setting.Name)
                {
                case "currencyCode":
                    settingDisplay.CurrencyCode = setting.Value;
                    break;

                case "nextOrderNumber":
                    if (!int.TryParse(setting.Value, out intValue))
                    {
                        intValue = 0;
                    }
                    settingDisplay.NextOrderNumber = intValue;
                    break;

                case "nextInvoiceNumber":
                    if (!int.TryParse(setting.Value, out intValue))
                    {
                        intValue = 0;
                    }
                    settingDisplay.NextInvoiceNumber = intValue;
                    break;

                case "nextShipmentNumber":
                    if (!int.TryParse(setting.Value, out intValue))
                    {
                        intValue = 0;
                    }
                    settingDisplay.NextShipmentNumber = intValue;
                    break;

                case "dateFormat":
                    settingDisplay.DateFormat = setting.Value;
                    break;

                case "timeFormat":
                    settingDisplay.TimeFormat = setting.Value;
                    break;

                case "unitSystem":
                    settingDisplay.UnitSystem = setting.Value;
                    break;

                case "globalShippable":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.GlobalShippable = boolValue;
                    break;

                case "globalTaxable":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.GlobalTaxable = boolValue;
                    break;

                case "globalTrackInventory":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.GlobalTrackInventory = boolValue;
                    break;

                case "globalShippingIsTaxable":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.GlobalShippingIsTaxable = boolValue;
                    break;

                case "hasDomainRecord":
                    if (!bool.TryParse(setting.Value, out boolValue))
                    {
                        boolValue = false;
                    }
                    settingDisplay.HasDomainRecord = boolValue;
                    break;

                case "migration":
                    Guid migrationKey;
                    try
                    {
                        migrationKey = new Guid(setting.Value);
                    }
                    catch (Exception ex)
                    {
                        migrationKey = Guid.Empty;
                    }
                    settingDisplay.MigrationKey = migrationKey;
                    break;

                case "globalTaxationApplication":
                    settingDisplay.GlobalTaxationApplication = (TaxationApplication)Enum.Parse(typeof(TaxationApplication), setting.Value);
                    break;

                case "defaultExtendedContentCulture":
                    settingDisplay.DefaultExtendedContentCulture = setting.Value;
                    break;

                default:
                    setting.Value = string.Empty;
                    break;
                }
            }
            return(settingDisplay);
        }