/// <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> /// Unlinks the external identifier from existing customer. /// </summary> /// <returns>A task.</returns> public virtual async Task UnlinkExternalIdFromExistingCustomer() { IStoreOperationsManager storeOperationsManager = Utilities.GetManagerFactory(this.EcommerceContext).GetManager <IStoreOperationsManager>(); await storeOperationsManager.UnlinkFromExistingCustomer(); }