/// <summary> /// Creates the address profile. /// </summary> /// <param name="id">The identifier.</param> /// <param name="profile">The profile.</param> /// <returns>The service provider result.</returns> protected ServiceProviderResult CreateAddressProfile(string id, ref Profile profile) { ServiceProviderResult result = new ServiceProviderResult { Success = true }; try { var createArgs = new CreateProfileArgs(); createArgs.InputParameters.Name = "Address"; createArgs.InputParameters.Id = id; CorePipeline.Run(CommerceConstants.PipelineNames.CreateProfile, createArgs); profile = createArgs.OutputParameters.CommerceProfile; } catch (Exception e) { result = new ServiceProviderResult { Success = false }; result.SystemMessages.Add(new SystemMessage { Message = e.Message }); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="TranslateCommerceAddressProfileToEntityRequest"/> class. /// </summary> /// <param name="sourceProfile">The source profile.</param> /// <param name="destinationParty">The destination party.</param> public TranslateCommerceAddressProfileToEntityRequest([NotNull] Profile sourceProfile, [NotNull] CommerceParty destinationParty) { Assert.ArgumentNotNull(sourceProfile, "commerceProfile"); Assert.ArgumentNotNull(destinationParty, "customerParty"); this.SourceProfile = sourceProfile; this.DestinationParty = destinationParty; }
/// <summary> /// Gets the specified profile. /// </summary> /// <typeparam name="T">Type of the property in the Commerce Server profile object.</typeparam> /// <param name="profile">The profile.</param> /// <param name="propertyName">Name of the property.</param> /// <returns> /// The Commerce Server profile property value. /// </returns> protected T Get <T>(Profile profile, string propertyName) { if (profile[propertyName].Value == System.DBNull.Value) { return(default(T)); } return((T)profile[propertyName].Value); }
/// <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, 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 <CommerceParty>("Party"); TranslateCommerceAddressProfileToEntityRequest requestToEntity = new TranslateCommerceAddressProfileToEntityRequest(addressProfile, newParty); PipelineUtility.RunCommerceConnectPipeline <TranslateCommerceAddressProfileToEntityRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateCommerceAddressProfileToEntity, requestToEntity); return(requestToEntity.DestinationParty); }
/// <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 AddPartiesRequest, "args.Request", "args.Request is AddPartiesRequest"); Assert.ArgumentCondition(args.Result is AddPartiesResult, "args.Result", "args.Result is AddPartiesResult"); var request = (AddPartiesRequest)args.Request; var result = (AddPartiesResult)args.Result; Assert.ArgumentNotNull(request.Parties, "request.Parties"); Assert.ArgumentNotNull(request.CommerceCustomer, "request.CommerceCustomer"); 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; } List <Party> partiesAdded = new List <Party>(); foreach (Party party in request.Parties) { if (party == null) { continue; } Party newParty = null; if (party is CommerceParty) { newParty = this.ProcessCommerceParty(result, customerProfile, party as CommerceParty); } else { newParty = this.ProcessCustomParty(result, customerProfile, party); } if (newParty != null) { partiesAdded.Add(newParty); } } }
/// <summary> /// Translates the commerce customer party. /// </summary> /// <param name="party">The party.</param> /// <param name="profile">The profile.</param> protected virtual void TranslateCommerceCustomerParty(CommerceParty party, Profile profile) { profile["GeneralInfo.first_name"].Value = party.FirstName; profile["GeneralInfo.last_name"].Value = party.LastName; profile["GeneralInfo.address_name"].Value = party.Name; profile["GeneralInfo.address_line1"].Value = party.Address1; profile["GeneralInfo.address_line2"].Value = party.Address2; profile["GeneralInfo.city"].Value = party.City; profile["GeneralInfo.region_code"].Value = party.RegionCode; profile["GeneralInfo.region_name"].Value = party.RegionName; profile["GeneralInfo.postal_code"].Value = party.ZipPostalCode; profile["GeneralInfo.country_code"].Value = party.CountryCode; profile["GeneralInfo.country_name"].Value = party.Country; profile["GeneralInfo.tel_number"].Value = party.PhoneNumber; profile["GeneralInfo.region_code"].Value = party.State; this.TranslateCommerceCustomerPartyCustomProperties(party, profile); }
/// <summary> /// Translates to commerce party. /// </summary> /// <param name="profile">The profile.</param> /// <param name="party">The party.</param> protected virtual void TranslateToCommerceParty(Profile profile, CommerceParty party) { party.ExternalId = this.Get <string>(profile, "GeneralInfo.address_id"); party.FirstName = this.Get <string>(profile, "GeneralInfo.first_name"); party.LastName = this.Get <string>(profile, "GeneralInfo.last_name"); party.Name = this.Get <string>(profile, "GeneralInfo.address_name"); party.Address1 = this.Get <string>(profile, "GeneralInfo.address_line1"); party.Address2 = this.Get <string>(profile, "GeneralInfo.address_line2"); party.City = this.Get <string>(profile, "GeneralInfo.city"); party.RegionCode = this.Get <string>(profile, "GeneralInfo.region_code"); party.RegionName = this.Get <string>(profile, "GeneralInfo.region_name"); party.ZipPostalCode = this.Get <string>(profile, "GeneralInfo.postal_code"); party.CountryCode = this.Get <string>(profile, "GeneralInfo.country_code"); party.Country = this.Get <string>(profile, "GeneralInfo.country_name"); party.PhoneNumber = this.Get <string>(profile, "GeneralInfo.tel_number"); party.State = this.Get <string>(profile, "GeneralInfo.region_code"); this.TranslateToCommercePartyCustomProperties(profile, party); }
/// <summary> /// Processes the custom party. /// </summary> /// <param name="result">The result.</param> /// <param name="customerProfile">The customer profile.</param> /// <param name="party">The party.</param> /// <returns>Newly created party.</returns> private Party ProcessCustomParty(AddPartiesResult result, Profile customerProfile, Party party) { return(null); }
/// <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> /// Translates the custom party. /// </summary> /// <param name="party">The party.</param> /// <param name="profile">The profile.</param> private void TranslateCustomParty(CommerceParty party, CommerceServer.Core.Runtime.Profiles.Profile profile) { }
/// <summary> /// Translates the commerce customer party custom properties. /// </summary> /// <param name="party">The party.</param> /// <param name="profile">The profile.</param> protected virtual void TranslateCommerceCustomerPartyCustomProperties(CommerceParty party, CommerceServer.Core.Runtime.Profiles.Profile profile) { }
/// <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 GetPartiesRequest, "args.Request", "args.Request is GetPartiesRequest"); Assert.ArgumentCondition(args.Result is GetPartiesResult, "args.Result", "args.Result is GetPartiesResult"); var request = (GetPartiesRequest)args.Request; var result = (GetPartiesResult)args.Result; Assert.ArgumentNotNull(request.CommerceCustomer, "request.CommerceCustomer"); List <Party> partyList = new List <Party>(); 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()); ProfilePropertyListCollection <string> addresIdsList = new ProfilePropertyListCollection <string>(e); if (addresIdsList != null) { foreach (string addressId in addresIdsList) { Profile commerceAddress = null; response = this.GetCommerceAddressProfile(addressId, ref commerceAddress); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } var newParty = this.EntityFactory.Create <CommerceParty>("Party"); var requestTorequestToEntity = new TranslateCommerceAddressProfileToEntityRequest(commerceAddress, newParty); PipelineUtility.RunCommerceConnectPipeline <TranslateCommerceAddressProfileToEntityRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateCommerceAddressProfileToEntity, requestTorequestToEntity); if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(newParty.ExternalId, System.StringComparison.OrdinalIgnoreCase)) { newParty.IsPrimary = true; } var address = requestTorequestToEntity.DestinationParty; partyList.Add(address); } } } result.Parties = partyList.AsReadOnly(); }
/// <summary> /// Translates the commerce customer party custom properties. /// </summary> /// <param name="party">The party.</param> /// <param name="profile">The profile.</param> protected virtual void TranslateCommerceCustomerPartyCustomProperties(CommerceParty party, Profile profile) { }
/// <summary> /// Initializes a new instance of the <see cref="TranslateEntityToCommerceAddressProfileRequest"/> class. /// </summary> /// <param name="sourceParty">The source party.</param> /// <param name="destinationProfile">The destination profile.</param> public TranslateEntityToCommerceAddressProfileRequest([NotNull] CommerceParty sourceParty, [NotNull] Profile destinationProfile) { Assert.ArgumentNotNull(destinationProfile, "commerceProfile"); Assert.ArgumentNotNull(sourceParty, "customerParty"); this.DestinationProfile = destinationProfile; this.SourceParty = sourceParty; }
/// <summary> /// Translates to commerce party custom properties. /// </summary> /// <param name="profile">The profile.</param> /// <param name="party">The party.</param> protected virtual void TranslateToCommercePartyCustomProperties(Profile profile, CommerceParty party) { }
/// <summary> /// Gets the commerce user profile. /// </summary> /// <param name="id">The identifier.</param> /// <param name="profile">The profile.</param> /// <returns>The service provider result.</returns> protected ServiceProviderResult GetCommerceUserProfile(string id, ref Profile profile) { return(this.GetCommerceProfile(id, "UserObject", ref profile)); }
/// <summary> /// Gets the commerce address profile. /// </summary> /// <param name="id">The identifier.</param> /// <param name="profile">The profile.</param> /// <returns>The service provider result.</returns> protected ServiceProviderResult GetCommerceAddressProfile(string id, ref Profile profile) { return(this.GetCommerceProfile(id, "Address", ref profile)); }
/// <summary> /// Translates to custom party. /// </summary> /// <param name="profile">The profile.</param> /// <param name="party">The party.</param> protected virtual void TranslateToCustomParty(Profile profile, Party party) { }
/// <summary> /// Translates the custom party. /// </summary> /// <param name="party">The party.</param> /// <param name="profile">The profile.</param> private void TranslateCustomParty(CommerceParty party, Profile profile) { }
/// <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 CommerceParty, "partyToUpdate is 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 (((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((CommerceParty)partyToUpdate, commerceAddress); PipelineUtility.RunCommerceConnectPipeline <TranslateEntityToCommerceAddressProfileRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateEntityToCommerceAddressProfile, translateToEntityRequest); commerceAddress.Update(); } } } }