public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, nameof(args)); Assert.ArgumentCondition(args.Request is GetPartiesRequest, nameof(args.Request), "args.Request is GetPartiesRequest"); Assert.ArgumentCondition(args.Result is GetPartiesResult, nameof(args.Result), "args.Result is GetPartiesResult"); var request = (GetPartiesRequest)args.Request; var result = (GetPartiesResult)args.Result; Assert.ArgumentNotNull(request.CommerceCustomer, nameof(request.CommerceCustomer)); var partyList = new List <Party>(); Profile customerProfile = null; var response = GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } var preferredAddress = customerProfile[Commerce.Constants.Profile.GeneralInfo.PreferredAddress].Value as string; var profileValue = customerProfile[Commerce.Constants.Profile.GeneralInfo.AddressList].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); var addresIdsList = new ProfilePropertyListCollection <string>(e); foreach (var addressId in addresIdsList) { Profile commerceAddress = null; response = GetCommerceAddressProfile(addressId, ref commerceAddress); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } var newParty = EntityFactory.Create <CommerceParty>("Party"); var requestTorequestToEntity = new TranslateCommerceAddressProfileToEntityRequest(commerceAddress, newParty); PipelineUtility.RunCommerceConnectPipeline <TranslateCommerceAddressProfileToEntityRequest, CommerceResult>(Constants.Pipelines.TranslateCommerceAddressProfileToEntity, requestTorequestToEntity); if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(newParty.ExternalId, StringComparison.OrdinalIgnoreCase)) { newParty.IsPrimary = true; } var address = requestTorequestToEntity.DestinationParty; partyList.Add(address); } } result.Parties = partyList.AsReadOnly(); }
private Party ProcessCommerceParty(AddPartiesResult result, Profile customerProfile, CommerceParty partyToAdd) { Assert.ArgumentNotNull(partyToAdd, nameof(partyToAdd)); Assert.ArgumentNotNull(partyToAdd.Name, nameof(partyToAdd.Name)); Assert.ArgumentNotNull(partyToAdd.ExternalId, nameof(partyToAdd.ExternalId)); Profile addressProfile = null; var response = CreateAddressProfile(partyToAdd.ExternalId, ref addressProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return(null); } var requestToCommerceProfile = new TranslateEntityToCommerceAddressProfileRequest(partyToAdd, addressProfile); PipelineUtility.RunCommerceConnectPipeline <TranslateEntityToCommerceAddressProfileRequest, CommerceResult>(Constants.Pipelines.TranslateEntityToCommerceAddressProfile, requestToCommerceProfile); addressProfile.Update(); ProfilePropertyListCollection <string> addressList; var profileValue = customerProfile[Commerce.Constants.Profile.GeneralInfo.AddressList].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); addressList = new ProfilePropertyListCollection <string>(e); } else { addressList = new ProfilePropertyListCollection <string>(); } addressList.Add(partyToAdd.ExternalId); customerProfile[Commerce.Constants.Profile.GeneralInfo.AddressList].Value = addressList.Cast <object>().ToArray(); if (partyToAdd.IsPrimary) { customerProfile[Commerce.Constants.Profile.GeneralInfo.PreferredAddress].Value = partyToAdd.ExternalId; } customerProfile.Update(); var newParty = EntityFactory.Create <CommerceParty>("Party"); var requestToEntity = new TranslateCommerceAddressProfileToEntityRequest(addressProfile, newParty); PipelineUtility.RunCommerceConnectPipeline <TranslateCommerceAddressProfileToEntityRequest, CommerceResult>(Constants.Pipelines.TranslateCommerceAddressProfileToEntity, requestToEntity); return(requestToEntity.DestinationParty); }
public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, nameof(args)); Assert.ArgumentCondition(args.Request is UpdatePartiesRequest, nameof(args.Request), "args.Request is UpdatePartiesRequest"); Assert.ArgumentCondition(args.Result is CustomerResult, nameof(args.Result), "args.Result is CustomerResult"); var request = (UpdatePartiesRequest)args.Request; var result = (CustomerResult)args.Result; Profile customerProfile = null; var response = GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } var preferredAddress = customerProfile[Commerce.Constants.Profile.GeneralInfo.PreferredAddress].Value as string; var profileValue = customerProfile[Commerce.Constants.Profile.GeneralInfo.AddressList].Value as object[]; if (profileValue == null) { return; } var e = profileValue.Select(i => i.ToString()); var addressList = new ProfilePropertyListCollection <string>(e); foreach (var partyToUpdate in request.Parties) { Assert.IsTrue(partyToUpdate is CommerceParty, "partyToUpdate is CommerceParty"); var foundId = addressList.FirstOrDefault(x => x.Equals(partyToUpdate.ExternalId, StringComparison.OrdinalIgnoreCase)); if (foundId == null) { continue; } Profile commerceAddress = null; response = GetCommerceAddressProfile(foundId, ref commerceAddress); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } // Check if the IsPrimary address flag has been flipped. if (((CommerceParty)partyToUpdate).IsPrimary) { customerProfile[Commerce.Constants.Profile.GeneralInfo.PreferredAddress].Value = partyToUpdate.ExternalId; customerProfile.Update(); } else if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(partyToUpdate.ExternalId, StringComparison.OrdinalIgnoreCase)) { customerProfile[Commerce.Constants.Profile.GeneralInfo.PreferredAddress].Value = DBNull.Value; customerProfile.Update(); } var translateToEntityRequest = new TranslateEntityToCommerceAddressProfileRequest((CommerceParty)partyToUpdate, commerceAddress); PipelineUtility.RunCommerceConnectPipeline <TranslateEntityToCommerceAddressProfileRequest, CommerceResult>(Constants.Pipelines.TranslateEntityToCommerceAddressProfile, translateToEntityRequest); commerceAddress.Update(); } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is RemovePartiesRequest, "args.Request", "args.Request is RemovePartiesRequest"); Assert.ArgumentCondition(args.Result is CustomerResult, "args.Result", "args.Result is CustomerResult"); var request = (RemovePartiesRequest)args.Request; var result = (CustomerResult)args.Result; Profile customerProfile = null; var response = this.GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } string preferredAddress = customerProfile["GeneralInfo.preferred_address"].Value as string; var profileValue = customerProfile["GeneralInfo.address_list"].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); var addressList = new ProfilePropertyListCollection <string>(e); foreach (var partyToRemove in request.Parties) { var foundId = addressList.Where(x => x.Equals(partyToRemove.ExternalId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (foundId != null) { response = this.DeleteAddressCommerceProfile(foundId); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } addressList.Remove(foundId); if (addressList.Count() == 0) { customerProfile["GeneralInfo.address_list"].Value = System.DBNull.Value; } else { customerProfile["GeneralInfo.address_list"].Value = addressList.Cast <object>().ToArray(); } // Preffered address check. If the address being deleted was the preferred address we must clear it from the customer profile. if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(partyToRemove.ExternalId, StringComparison.OrdinalIgnoreCase)) { customerProfile["GeneralInfo.preferred_address"].Value = System.DBNull.Value; } customerProfile.Update(); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is RemovePartiesRequest, "args.Request", "args.Request is RemovePartiesRequest"); Assert.ArgumentCondition(args.Result is CustomerResult, "args.Result", "args.Result is CustomerResult"); var request = (RemovePartiesRequest)args.Request; var result = (CustomerResult)args.Result; Profile customerProfile = null; var response = this.GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } string preferredAddress = customerProfile["GeneralInfo.preferred_address"].Value as string; var profileValue = customerProfile["GeneralInfo.address_list"].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); var addressList = new ProfilePropertyListCollection<string>(e); foreach (var partyToRemove in request.Parties) { var foundId = addressList.Where(x => x.Equals(partyToRemove.ExternalId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (foundId != null) { response = this.DeleteAddressCommerceProfile(foundId); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } addressList.Remove(foundId); if (addressList.Count() == 0) { customerProfile["GeneralInfo.address_list"].Value = System.DBNull.Value; } else { customerProfile["GeneralInfo.address_list"].Value = addressList.Cast<object>().ToArray(); } // Preffered address check. If the address being deleted was the preferred address we must clear it from the customer profile. if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(partyToRemove.ExternalId, StringComparison.OrdinalIgnoreCase)) { customerProfile["GeneralInfo.preferred_address"].Value = System.DBNull.Value; } customerProfile.Update(); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is UpdatePartiesRequest, "args.Request", "args.Request is UpdatePartiesRequest"); Assert.ArgumentCondition(args.Result is CustomerResult, "args.Result", "args.Result is CustomerResult"); var request = (UpdatePartiesRequest)args.Request; var result = (CustomerResult)args.Result; Profile customerProfile = null; var response = this.GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } string preferredAddress = customerProfile["GeneralInfo.preferred_address"].Value as string; var profileValue = customerProfile["GeneralInfo.address_list"].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); var addressList = new ProfilePropertyListCollection<string>(e); foreach (var partyToUpdate in request.Parties) { Assert.IsTrue(partyToUpdate is RefSFModels.CommerceParty, "partyToUpdate is RefSFModels.CommerceParty"); var foundId = addressList.Where(x => x.Equals(partyToUpdate.ExternalId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (foundId != null) { Profile commerceAddress = null; response = this.GetCommerceAddressProfile(foundId, ref commerceAddress); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } // Check if the IsPrimary address flag has been flipped. if (((RefSFModels.CommerceParty)partyToUpdate).IsPrimary) { customerProfile["GeneralInfo.preferred_address"].Value = partyToUpdate.ExternalId; customerProfile.Update(); } else if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(partyToUpdate.ExternalId, StringComparison.OrdinalIgnoreCase)) { customerProfile["GeneralInfo.preferred_address"].Value = System.DBNull.Value; customerProfile.Update(); } var translateToEntityRequest = new TranslateEntityToCommerceAddressProfileRequest((RefSFModels.CommerceParty)partyToUpdate, commerceAddress); PipelineUtility.RunCommerceConnectPipeline<TranslateEntityToCommerceAddressProfileRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateEntityToCommerceAddressProfile, translateToEntityRequest); commerceAddress.Update(); } } } }
/// <summary> /// Processes the commerce party. /// </summary> /// <param name="result">The result.</param> /// <param name="customerProfile">The customer profile.</param> /// <param name="partyToAdd">The party to add.</param> /// <returns>Newly created party.</returns> protected virtual Party ProcessCommerceParty(AddPartiesResult result, Profile customerProfile, RefSFModels.CommerceParty partyToAdd) { Assert.ArgumentNotNull(partyToAdd.Name, "partyToAdd.Name"); Assert.ArgumentNotNull(partyToAdd.ExternalId, "partyToAdd.ExternalId"); Profile addressProfile = null; var response = this.CreateAddressProfile(partyToAdd.ExternalId, ref addressProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return null; } var requestToCommerceProfile = new TranslateEntityToCommerceAddressProfileRequest(partyToAdd, addressProfile); PipelineUtility.RunCommerceConnectPipeline<TranslateEntityToCommerceAddressProfileRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateEntityToCommerceAddressProfile, requestToCommerceProfile); addressProfile.Update(); ProfilePropertyListCollection<string> addressList; var profileValue = customerProfile["GeneralInfo.address_list"].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); addressList = new ProfilePropertyListCollection<string>(e); } else { addressList = new ProfilePropertyListCollection<string>(); } addressList.Add(partyToAdd.ExternalId); customerProfile["GeneralInfo.address_list"].Value = addressList.Cast<object>().ToArray(); if (partyToAdd.IsPrimary) { customerProfile["GeneralInfo.preferred_address"].Value = partyToAdd.ExternalId; } customerProfile.Update(); var newParty = this.EntityFactory.Create<RefSFModels.CommerceParty>("Party"); TranslateCommerceAddressProfileToEntityRequest requestToEntity = new TranslateCommerceAddressProfileToEntityRequest(addressProfile, newParty); PipelineUtility.RunCommerceConnectPipeline<TranslateCommerceAddressProfileToEntityRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateCommerceAddressProfileToEntity, requestToEntity); return requestToEntity.DestinationParty; }