/// <summary> /// Gets the channel currency string template. /// </summary> /// <param name="ecommerceContext">The eCommerce context.</param> /// <returns>The template for channel currency string.</returns> public static async Task <string> GetChannelCurrencyStringTemplate(EcommerceContext ecommerceContext) { OperatingUnitConfiguration operatingUnitConfig = null; if (cachedOperatingUnitConfig.TryGetValue(ecommerceContext.OperatingUnitId, out operatingUnitConfig)) { if (!string.IsNullOrEmpty(operatingUnitConfig.CurrencyStringTemplate)) { return(operatingUnitConfig.CurrencyStringTemplate); } } ManagerFactory factory = Utilities.GetManagerFactory(ecommerceContext); IOrgUnitManager orgUnitManager = factory.GetManager <IOrgUnitManager>(); ChannelConfiguration channelConfiguration = await orgUnitManager.GetOrgUnitConfiguration(); string currencySymbol = Utilities.GetChannelCurrencySymbol(channelConfiguration.Currency); CultureInfo cultureInfo = Utilities.GetCultureInfo(ecommerceContext.Locale); NumberFormatInfo nfi = cultureInfo.NumberFormat; bool symbolToTheRight = (nfi.CurrencyPositivePattern % 2 == 0) ? false : true; string currencyTemplate = symbolToTheRight ? "{0}" + currencySymbol : currencySymbol + "{0}"; // Update cache Utilities.cachedOperatingUnitConfig[ecommerceContext.OperatingUnitId].CurrencySymbol = currencySymbol; Utilities.cachedOperatingUnitConfig[ecommerceContext.OperatingUnitId].CurrencyStringTemplate = currencyTemplate; return(currencyTemplate); }
/// <summary> /// Gets the channel identifier. /// </summary> /// <param name="ecommerceContext">The ecommerce context.</param> /// <returns>The channel identifier.</returns> public static async Task <long> GetChannelId(EcommerceContext ecommerceContext) { OperatingUnitConfiguration operatingUnitConfig = null; if (cachedOperatingUnitConfig.TryGetValue(ecommerceContext.OperatingUnitId, out operatingUnitConfig)) { if (operatingUnitConfig.ChannelId != 0) { return(operatingUnitConfig.ChannelId); } } ManagerFactory factory = Utilities.GetManagerFactory(ecommerceContext); IOrgUnitManager orgUnitManager = factory.GetManager <IOrgUnitManager>(); ChannelConfiguration channelConfiguration = await orgUnitManager.GetOrgUnitConfiguration(); // Update cache Utilities.cachedOperatingUnitConfig[ecommerceContext.OperatingUnitId].ChannelId = channelConfiguration.RecordId; return(channelConfiguration.RecordId); }
/// <summary> /// Gets factory initialized by the id_token. /// </summary> /// <param name="ecommerceContext">The eCommerce context.</param> /// <returns>The factory.</returns> public static ManagerFactory GetManagerFactory(EcommerceContext ecommerceContext) { if (ecommerceContext == null) { throw new ArgumentNullException(nameof(ecommerceContext)); } if (string.IsNullOrEmpty(ecommerceContext.OperatingUnitId)) { RetailLogger.Log.OnlineStoreOperatingUnitNumberNotSetInEcommerceContext(); var exception = new NotSupportedException("The operating unit number must be set in the eCommerce context."); throw exception; } Uri retailServerUri = null; OperatingUnitConfiguration operatingUnitConfig = null; if (!cachedOperatingUnitConfig.TryGetValue(ecommerceContext.OperatingUnitId, out operatingUnitConfig)) { lock (syncRoot) { if (!cachedOperatingUnitConfig.TryGetValue(ecommerceContext.OperatingUnitId, out operatingUnitConfig)) { retailServerUri = new Uri(ConfigurationManager.AppSettings["RetailServerRoot"]); operatingUnitConfig = new OperatingUnitConfiguration() { RetailServerUri = retailServerUri }; cachedOperatingUnitConfig.Add(ecommerceContext.OperatingUnitId, operatingUnitConfig); } } } else { retailServerUri = operatingUnitConfig.RetailServerUri; } ManagerFactory managerFactory = null; RetailServerContext context = null; if (string.IsNullOrEmpty(ecommerceContext.AuthenticationToken)) { context = RetailServerContext.Create(retailServerUri, ecommerceContext.OperatingUnitId); } else { if (ecommerceContext.IdentityProviderType == IdentityProviderType.OpenIdConnect) { context = RetailServerContext.Create(retailServerUri, ecommerceContext.OperatingUnitId, ecommerceContext.AuthenticationToken); } else if (ecommerceContext.IdentityProviderType == IdentityProviderType.ACS) { context = RetailServerContext.Create(retailServerUri, ecommerceContext.OperatingUnitId, new AcsToken(ecommerceContext.AuthenticationToken)); } else { RetailLogger.Log.OnlineStoreUnsupportedIdentityProviderTypeEncountered(ecommerceContext.IdentityProviderType.ToString()); string message = string.Format("The specified identity provider type [{0}] set in the eCommerce context is not supported.", ecommerceContext.IdentityProviderType); var exception = new NotSupportedException(message); throw exception; } } context.Locale = ecommerceContext.Locale; managerFactory = ManagerFactory.Create(context); return(managerFactory); }