internal static string ReadMultiStoreItemFromPropertiesDictionary(string propertyAlias, ILocalization localization, IPropertyProvider fields)
        {
            var currencyCode    = localization.CurrencyCode;
            var storeAlias      = localization.StoreAlias;
            var multiStoreAlias = CreateMultiStorePropertyAlias(propertyAlias, storeAlias);

            if (!string.IsNullOrEmpty(currencyCode))
            {
                if (!string.IsNullOrEmpty(storeAlias))
                {
                    var multiStoreMultiCurrenyAlias = CreateFullLocalizedPropertyAlias(propertyAlias, localization);
                    if (fields.ContainsKey(multiStoreMultiCurrenyAlias))
                    {
                        var value = fields.GetStringValue(multiStoreMultiCurrenyAlias);

                        if (!string.IsNullOrEmpty(value))
                        {
                            return(value);
                        }
                    }
                }
                var multiCurrencyAlias = CreateMultiStorePropertyAlias(propertyAlias, currencyCode);
                if (fields.ContainsKey(multiCurrencyAlias))
                {
                    var value = fields.GetStringValue(multiCurrencyAlias);

                    if (!string.IsNullOrEmpty(value))
                    {
                        return(value);
                    }
                }
            }

            if (!string.IsNullOrEmpty(storeAlias))
            {
                if (fields.ContainsKey(multiStoreAlias))
                {
                    var value = fields.GetStringValue(multiStoreAlias);

                    if (!string.IsNullOrEmpty(value))
                    {
                        return(value);
                    }
                }
            }
            if (fields.ContainsKey(propertyAlias))
            {
                var value = fields.GetStringValue(propertyAlias);

                return(value ?? string.Empty);
            }
            return(string.Empty);
        }
Exemple #2
0
 private string FieldsValueOrEmpty(string propertyAlias, IPropertyProvider fields)
 {
     if (fields.ContainsKey(propertyAlias))
     {
         return(fields.GetStringValue(propertyAlias));
     }
     return(string.Empty);
 }
        internal static int GetLocalizedPrice(string propertyAlias, ILocalization localization, IPropertyProvider fields)
        {
            int price;
            var fullLocalizedPricePropetryAlias = CreateFullLocalizedPropertyAlias(propertyAlias, localization);

            if (fields.ContainsKey(fullLocalizedPricePropetryAlias) && int.TryParse(fields.GetStringValue(fullLocalizedPricePropetryAlias), out price))
            {
                return(price);
            }
            var localizedPricePropertyAlias = CreateMultiStorePropertyAlias(propertyAlias, localization.CurrencyCode);

            if (fields.ContainsKey(localizedPricePropertyAlias) && int.TryParse(fields.GetStringValue(localizedPricePropertyAlias), out price))
            {
                return(price);
            }
            price = GetMultiStoreIntValue(propertyAlias, localization, fields);
            return(LocalizePrice(price, localization));
        }
        internal static bool GetMultiStoreDisableExamine(ILocalization localization, IPropertyProvider fields)
        {
            const string        propertyAlias = "disable";
            Func <string, bool> valueCheck    = value => value == "1" || value == "true";

            if (fields.ContainsKey(propertyAlias) && valueCheck(fields.GetStringValue(propertyAlias)))
            {
                return(true);
            }

            var val = ReadMultiStoreItemFromPropertiesDictionary(propertyAlias, localization, fields);

            return(valueCheck(val));
        }
		///// <summary>
		///// Loads the data from examine.
		///// </summary>
		///// <param name="storeAlias">The store alias.</param>
		///// <param name="examineNode">The examine node.</param>
		///// <returns></returns>
		//protected virtual bool LoadDataFromExamine(string storeAlias, SearchResult examineNode = null)
		//{
		//	//Log.Instance.LogDebug( DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "LoadDataFromExamine::NodeBase start"); 
		//	bool logAtEnd = false;
		//	if (examineNode == null)
		//	{
		//		logAtEnd = true;
		//		examineNode = StoreHelper.GetNodeFromExamine(_nodeId);
		//	}
		//	if (examineNode == null)
		//	{
		//		return false;
		//	}

		//	LoadFieldsFromExamine(new DictionaryPropertyProvider(examineNode));

		//	//if (logAtEnd)
		//	//    Log.Instance.LogDebug(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "END LoadDataFromExamine::NodeBase typealias:" + _nodeTypeAlias);
		//	return true;
		//}

		internal virtual void LoadFieldsFromExamine(IPropertyProvider fields)
		{
			string stringValue = null;
			if (_nodeId == 0 && fields.UpdateValueIfPropertyPresent("id", ref stringValue))
			{
				int.TryParse(stringValue, out _nodeId);
			}

			if (fields.UpdateValueIfPropertyPresent("parentID", ref stringValue))
			{
				int intVal;
				if (int.TryParse(stringValue, out intVal))
					_parentId = intVal;
			}

			if (fields.ContainsKey("sortOrder"))
			{
				string value = fields.GetStringValue("sortOrder");
				int sortOrder;
				if (Int32.TryParse(value, out sortOrder))
					_sortOrder = sortOrder;
			}
			//if (_nodeId == 0)
			//	_nodeId = GetIntValue("id", examineNode).GetValueOrDefault(); can't use multistore here!!!! -> vanwege Store (will cause endless loop)
			//_parentId = GetIntValue("parentID", examineNode);  can't use multistore here!!!! -> vanwege Store
			//_sortOrder = GetIntValue("sortOrder", examineNode); can't use multistore here!!!! -> vanwege Store

			if (fields.ContainsKey("nodeTypeAlias"))
			{
				_nodeTypeAlias = fields.GetStringValue("nodeTypeAlias");
			}
			if (fields.ContainsKey("nodeName"))
			{
				_nodeName = fields.GetStringValue("nodeName");
				if (_nodeName == string.Empty) throw new Exception("Node with empty name");
			}
			if (fields.ContainsKey("path"))
			{
				_path = fields.GetStringValue("path");
			}
			if (fields.ContainsKey("createDate"))
			{
				string value = fields.GetStringValue("createDate");
				DateTime date;
				if (DateTime.TryParse(value, out date)) // todo: use the right culture!
					_createDate = date;
			}
			if (fields.ContainsKey("updateDate"))
			{
				string value = fields.GetStringValue("updateDate");
				DateTime date;
				if (DateTime.TryParse(value, out date)) // todo: use the right culture!
					_updateDate = date;
			}
			if (fields.ContainsKey("urlName"))
			{
				_urlName = fields.GetStringValue("urlName");
			}
		}
Exemple #6
0
        ///// <summary>
        ///// Loads the data from examine.
        ///// </summary>
        ///// <param name="storeAlias">The store alias.</param>
        ///// <param name="examineNode">The examine node.</param>
        ///// <returns></returns>
        //protected virtual bool LoadDataFromExamine(string storeAlias, SearchResult examineNode = null)
        //{
        //	//Log.Instance.LogDebug( DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "LoadDataFromExamine::NodeBase start");
        //	bool logAtEnd = false;
        //	if (examineNode == null)
        //	{
        //		logAtEnd = true;
        //		examineNode = StoreHelper.GetNodeFromExamine(_nodeId);
        //	}
        //	if (examineNode == null)
        //	{
        //		return false;
        //	}

        //	LoadFieldsFromExamine(new DictionaryPropertyProvider(examineNode));

        //	//if (logAtEnd)
        //	//    Log.Instance.LogDebug(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "END LoadDataFromExamine::NodeBase typealias:" + _nodeTypeAlias);
        //	return true;
        //}

        internal virtual void LoadFieldsFromExamine(IPropertyProvider fields)
        {
            string stringValue = null;

            if (_nodeId == 0 && fields.UpdateValueIfPropertyPresent("id", ref stringValue))
            {
                int.TryParse(stringValue, out _nodeId);
            }

            if (fields.UpdateValueIfPropertyPresent("parentID", ref stringValue))
            {
                int intVal;
                if (int.TryParse(stringValue, out intVal))
                {
                    _parentId = intVal;
                }
            }

            if (fields.ContainsKey("sortOrder"))
            {
                string value = fields.GetStringValue("sortOrder");
                int    sortOrder;
                if (Int32.TryParse(value, out sortOrder))
                {
                    _sortOrder = sortOrder;
                }
            }
            //if (_nodeId == 0)
            //	_nodeId = GetIntValue("id", examineNode).GetValueOrDefault(); can't use multistore here!!!! -> vanwege Store (will cause endless loop)
            //_parentId = GetIntValue("parentID", examineNode);  can't use multistore here!!!! -> vanwege Store
            //_sortOrder = GetIntValue("sortOrder", examineNode); can't use multistore here!!!! -> vanwege Store

            if (fields.ContainsKey("nodeTypeAlias"))
            {
                _nodeTypeAlias = fields.GetStringValue("nodeTypeAlias");
            }
            if (fields.ContainsKey("nodeName"))
            {
                _nodeName = fields.GetStringValue("nodeName");
                if (_nodeName == string.Empty)
                {
                    throw new Exception("Node with empty name");
                }
            }
            if (fields.ContainsKey("path"))
            {
                _path = fields.GetStringValue("path");
            }
            if (fields.ContainsKey("createDate"))
            {
                string   value = fields.GetStringValue("createDate");
                DateTime date;
                if (DateTime.TryParse(value, out date))                 // todo: use the right culture!
                {
                    _createDate = date;
                }
            }
            if (fields.ContainsKey("updateDate"))
            {
                string   value = fields.GetStringValue("updateDate");
                DateTime date;
                if (DateTime.TryParse(value, out date))                 // todo: use the right culture!
                {
                    _updateDate = date;
                }
            }
            if (fields.ContainsKey("urlName"))
            {
                _urlName = fields.GetStringValue("urlName");
            }
        }
Exemple #7
0
            public override void LoadDataFromPropertiesDictionary(Store store, IPropertyProvider fields, ILocalization localization)
            {
                // note: it's impossible to use StoreHelper.GetMultiStoreItemExamine here (or any multi store)

                if (fields.ContainsKey("incompleteOrderLifetime"))
                {
                    double incompleteOrderLifetime;
                    if (double.TryParse(fields.GetStringValue("incompleteOrderLifetime"), out incompleteOrderLifetime))
                    {
                        store.IncompleOrderLifetime = incompleteOrderLifetime;
                    }
                }
                if (fields.ContainsKey("globalVat"))
                {
                    var vatProperty = fields.GetStringValue("globalVat");
                    if (!string.IsNullOrEmpty(vatProperty))
                    {
                        if (vatProperty.ToLowerInvariant() != "default")
                        {
                            vatProperty = vatProperty.Replace(',', '.');

                            var vat = Convert.ToDecimal(vatProperty, CultureInfo.InvariantCulture);

                            store.GlobalVat = vat;
                        }
                        else
                        {
                            store.GlobalVat = 0;
                        }
                    }
                }
                if (fields.ContainsKey("storeCulture"))
                {
                    var culture    = fields.GetStringValue("storeCulture");
                    int languageId = 0;

                    if (culture != null)
                    {
                        int.TryParse(culture, out languageId);
                    }

                    if (languageId != 0)
                    {
                        var matchedLanguage = Language.GetAllAsList().FirstOrDefault(x => x.id == languageId);
                        if (matchedLanguage != null)
                        {
                            store.Culture = new Language(languageId).CultureAlias;
                        }
                        else
                        {
                            var firstOrDefault = Language.GetAllAsList().FirstOrDefault();
                            if (firstOrDefault != null)
                            {
                                store.Culture = firstOrDefault.CultureAlias;
                            }
                            else
                            {
                                store.Culture = string.Empty;
                            }
                        }
                    }
                    else
                    {
                        store.Culture = string.Empty;
                    }
                }
                if (fields.ContainsKey("countryCode"))
                {
                    store.CountryCode = fields.GetStringValue("countryCode");
                }
                if (fields.ContainsKey("defaultCountryCode"))
                {
                    store.DefaultCountryCode = fields.GetStringValue("defaultCountryCode");
                }
                if (fields.ContainsKey("currencyCulture"))
                {
                    // this is for backwards compatiblity
                    var culture    = fields.GetStringValue("currencyCulture");
                    var languageId = 0;

                    if (culture != null)
                    {
                        int.TryParse(culture, out languageId);
                    }

                    store.CurrencyCulture = languageId != 0 ? new Language(languageId).CultureAlias : string.Empty;
                }
                RegionInfo currencyRegion;

                if (fields.ContainsKey("currencyCulture"))
                {
                    var currencyCulture = new CultureInfo(store.CurrencyCulture);
                    currencyRegion = new RegionInfo(currencyCulture.LCID);
                }
                else
                {
                    currencyRegion = new RegionInfo(store.CultureInfo.LCID);
                }
                var cultureCurrency = currencyRegion.ISOCurrencySymbol;

                if (fields.ContainsKey("currencies"))
                {
                    // "EUR|1.1#USD|0.7#JPY|1"
                    var currenciesfromfield = fields.GetStringValue("currencies").Split('#').Select(x => new Currency(x)).ToList();

                    if (!currenciesfromfield.Any(c => c.ISOCurrencySymbol == cultureCurrency))
                    {
                        currenciesfromfield.Add(new Currency {
                            ISOCurrencySymbol = cultureCurrency, Ratio = 1, CurrencySymbol = currencyRegion.CurrencySymbol
                        });
                    }

                    store.Currencies    = currenciesfromfield;
                    store.CurrencyCodes = store.Currencies.Select(c => c.ISOCurrencySymbol).ToList();
                }
                else
                {
                    store.Currencies = new[] { new Currency {
                                                   ISOCurrencySymbol = cultureCurrency, Ratio = 1, CurrencySymbol = currencyRegion.CurrencySymbol
                                               } };
                    store.CurrencyCodes = new[] { cultureCurrency };
                }
                if (fields.ContainsKey("orderNumberPrefix"))
                {
                    store.OrderNumberPrefix = fields.GetStringValue("orderNumberPrefix");
                }
                if (fields.ContainsKey("orderNumberTemplate"))
                {
                    store.OrderNumberTemplate = fields.GetStringValue("orderNumberTemplate");
                }
                if (fields.ContainsKey("orderNumberStartNumber"))
                {
                    int orderNumberStartNumber;
                    if (int.TryParse(fields.GetStringValue("orderNumberStartNumber"), out orderNumberStartNumber))
                    {
                        store.OrderNumberStartNumber = orderNumberStartNumber;
                    }
                }
                if (fields.ContainsKey("enableStock"))
                {
                    var enableStockValue = fields.GetStringValue("enableStock");
                    store.UseStock = enableStockValue == "enable" || enableStockValue == "1" || enableStockValue == "true";
                }
                if (fields.ContainsKey("defaultUseVariantStock"))
                {
                    var enableStockValue = fields.GetStringValue("defaultUseVariantStock");
                    store.UseVariantStock = enableStockValue == "enable" || enableStockValue == "1" || enableStockValue == "true";
                }

                if (fields.ContainsKey("defaultCountdownEnabled"))
                {
                    var enableCountdownValue = fields.GetStringValue("defaultCountdownEnabled");
                    store.UseCountdown = enableCountdownValue == "enable" || enableCountdownValue == "1" || enableCountdownValue == "true";
                }

                if (fields.ContainsKey("storeStock"))
                {
                    var storeStockValue = fields.GetStringValue("storeStock");
                    var value           = storeStockValue == "enable" || storeStockValue == "1" || storeStockValue == "true";
                    if (value)
                    {
                        var productDt = DocumentType.GetByAlias(Product.NodeAlias);
                        if (!productDt.PropertyTypes.Any(x => x.Alias.ToLower() == "stock_" + store.Alias.ToLower()))
                        {
                            value = false;
                        }
                    }
                    store.UseStoreSpecificStock = value;
                }

                if (fields.ContainsKey("useBackorders"))
                {
                    string useBackorders = fields.GetStringValue("useBackorders");

                    store.UseBackorders = useBackorders == "enable" || useBackorders == "1" || useBackorders == "true";
                }

                if (fields.ContainsKey("enableTestmode"))
                {
                    string enableTestmode = fields.GetStringValue("enableTestmode");

                    store.EnableTestmode = enableTestmode == "enable" || enableTestmode == "1" || enableTestmode == "true";
                }

                store.EmailAddressFrom                 = FieldsValueOrEmpty("storeEmailFrom", fields);
                store.EmailAddressFromName             = FieldsValueOrEmpty("storeEmailFromName", fields);
                store.EmailAddressTo                   = FieldsValueOrEmpty("storeEmailTo", fields);
                store.AccountCreatedEmail              = FieldsValueOrEmpty("accountEmailCreated", fields);
                store.AccountForgotPasswordEmail       = FieldsValueOrEmpty("accountForgotPassword", fields);
                store.ConfirmationEmailStore           = FieldsValueOrEmpty("confirmationEmailStore", fields);
                store.ConfirmationEmailCustomer        = FieldsValueOrEmpty("confirmationEmailCustomer", fields);
                store.OnlinePaymentEmailStore          = FieldsValueOrEmpty("onlinePaymentEmailStore", fields);
                store.OnlinePaymentEmailCustomer       = FieldsValueOrEmpty("onlinePaymentEmailCustomer", fields);
                store.OfflinePaymentEmailStore         = FieldsValueOrEmpty("offlinePaymentEmailStore", fields);
                store.OfflinePaymentEmailCustomer      = FieldsValueOrEmpty("offlinePaymentEmailCustomer", fields);
                store.PaymentFailedEmailStore          = FieldsValueOrEmpty("paymentFailedEmailStore", fields);
                store.PaymentFailedEmailCustomer       = FieldsValueOrEmpty("paymentFailedEmailCustomer", fields);
                store.DispatchedEmailStore             = FieldsValueOrEmpty("dispatchedEmailStore", fields);
                store.DispatchEmailCustomer            = FieldsValueOrEmpty("dispatchedEmailCustomer", fields);
                store.CancelEmailStore                 = FieldsValueOrEmpty("cancelEmailStore", fields);
                store.CancelEmailCustomer              = FieldsValueOrEmpty("cancelEmailCustomer", fields);
                store.ClosedEmailStore                 = FieldsValueOrEmpty("closedEmailStore", fields);
                store.ClosedEmailCustomer              = FieldsValueOrEmpty("closedEmailCustomer", fields);
                store.PendingEmailStore                = FieldsValueOrEmpty("pendingEmailStore", fields);
                store.PendingEmailCustomer             = FieldsValueOrEmpty("pendingEmailCustomer", fields);
                store.TemporaryOutOfStockEmailStore    = FieldsValueOrEmpty("temporaryOutOfStockEmailStore", fields);
                store.TemporaryOutOfStockEmailCustomer = FieldsValueOrEmpty("temporaryOutOfStockEmailCustomer", fields);
                store.UndeliverableEmailStore          = FieldsValueOrEmpty("undeliverableEmailStore", fields);
                store.UndeliverableEmailCustomer       = FieldsValueOrEmpty("undeliverableEmailCustomer", fields);
                store.ReturnedEmailStore               = FieldsValueOrEmpty("returnEmailStore", fields);
                store.ReturnedEmailCustomer            = FieldsValueOrEmpty("returnEmailCustomer", fields);
            }