/// <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 configuration. /// </summary> /// <returns>The channel configuration.</returns> public virtual async Task <ChannelConfiguration> GetChannelConfiguration() { ManagerFactory managerFactory = Utilities.GetManagerFactory(this.EcommerceContext); IOrgUnitManager orgUnitManager = managerFactory.GetManager <IOrgUnitManager>(); ChannelConfiguration channelConfiguration = await orgUnitManager.GetOrgUnitConfiguration(); return(channelConfiguration); }
/// <summary> /// Creates the specified customer. /// </summary> /// <param name="customer">The customer.</param> /// <returns>The created customer.</returns> public virtual async Task <Customer> Create(Customer customer) { // An empty ecommerce context is explicitly passed in because this needs to be an anonymous call. IOrgUnitManager orgUnitManager = Utilities.GetManagerFactory(this.EcommerceContext.GetAnonymousContext()).GetManager <IOrgUnitManager>(); ChannelConfiguration channelConfiguration = await orgUnitManager.GetOrgUnitConfiguration(); customer.Language = channelConfiguration.DefaultLanguageId; customer.CustomerTypeValue = 1; // To denote this is a CustomerType.Person. ManagerFactory factory = Utilities.GetManagerFactory(this.EcommerceContext); ICustomerManager customerManager = factory.GetManager <ICustomerManager>(); Customer createdCustomer = null; try { createdCustomer = await customerManager.Create(customer); } catch (UserAuthorizationException ex) { if (ex.ErrorResourceId == AuthenticationErrors.UserNotActivated) { var message = "There is already an inactive account associated with the current external id. Need to unlink first."; RetailLogger.Log.OnlineStoreCreatingNewCustomerForExternalIdWithInactiveLinkToExistingCustomer( Utilities.GetMaskedEmailAddress(customer.Email), this.EcommerceContext.IdentityProviderType.ToString(), message); IStoreOperationsManager storeOperationsManager = factory.GetManager <IStoreOperationsManager>(); await storeOperationsManager.UnlinkFromExistingCustomer(); createdCustomer = await customerManager.Create(customer); } else { throw ex; } } return(createdCustomer); }
/// <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); }