/// <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] RefSFModels.CommerceParty sourceParty, [NotNull] Profile destinationProfile) { Assert.ArgumentNotNull(destinationProfile, "commerceProfile"); Assert.ArgumentNotNull(sourceParty, "customerParty"); this.DestinationProfile = destinationProfile; this.SourceParty = sourceParty; }
/// <summary> /// Translates the commerce customer party. /// </summary> /// <param name="party">The party.</param> /// <param name="profile">The profile.</param> protected virtual void TranslateCommerceCustomerParty(RefSFModels.CommerceParty party, CommerceServer.Core.Runtime.Profiles.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> /// Sets the primary address. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="addressExternalId">The address external identifier.</param> /// <returns>The manager responsed with the success flag in the result.</returns> public virtual ManagerResponse <CustomerResult, bool> SetPrimaryAddress([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] string addressExternalId) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNullOrEmpty(addressExternalId, "addressExternalId"); var userPartiesResponse = this.GetCurrentCustomerParties(storefront, visitorContext); if (userPartiesResponse.ServiceProviderResult.Success) { var customerResult = new CustomerResult { Success = false }; customerResult.SystemMessages.ToList().AddRange(userPartiesResponse.ServiceProviderResult.SystemMessages); return(new ManagerResponse <CustomerResult, bool>(customerResult, false)); } var addressesToUpdate = new List <CSFConnectModels.CommerceParty>(); CSFConnectModels.CommerceParty notPrimary = (CSFConnectModels.CommerceParty)userPartiesResponse.Result.SingleOrDefault(address => ((CSFConnectModels.CommerceParty)address).IsPrimary); if (notPrimary != null) { notPrimary.IsPrimary = false; addressesToUpdate.Add(notPrimary); } var primaryAddress = (CSFConnectModels.CommerceParty)userPartiesResponse.Result.Single(address => address.PartyId == addressExternalId); //primaryAddress.IsPrimary = true; addressesToUpdate.Add(primaryAddress); var updatePartiesResponse = this.UpdateParties(storefront, new CommerceCustomer { ExternalId = visitorContext.UserId }, addressesToUpdate.Cast <Party>().ToList()); return(new ManagerResponse <CustomerResult, bool>(updatePartiesResponse.ServiceProviderResult, updatePartiesResponse.Result)); }
/// <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); }
public JsonResult AddressModify(PartyInputModelItem model) { try { Assert.ArgumentNotNull(model, "model"); var validationResult = new BaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return Json(validationResult, JsonRequestBehavior.AllowGet); } var addresses = new List<CSFConnectModels.CommerceParty>(); var userResponse = this.AccountManager.GetUser(Context.User.Name); var result = new AddressListItemJsonResult(userResponse.ServiceProviderResult); if (userResponse.ServiceProviderResult.Success && userResponse.Result != null) { var commerceUser = userResponse.Result; var customer = new CommerceCustomer { ExternalId = commerceUser.ExternalId }; var party = new CSFConnectModels.CommerceParty { ExternalId = model.ExternalId, Name = model.Name, Address1 = model.Address1, City = model.City, Country = model.Country, State = model.State, ZipPostalCode = model.ZipPostalCode, PartyId = model.PartyId, IsPrimary = model.IsPrimary }; if (string.IsNullOrEmpty(party.ExternalId)) { // Verify we have not reached the maximum number of addresses supported. int numberOfAddresses = this.AllAddresses(result).Count; if (numberOfAddresses >= StorefrontManager.CurrentStorefront.MaxNumberOfAddresses) { var message = StorefrontManager.GetSystemMessage("MaxAddresseLimitReached"); result.Errors.Add(string.Format(CultureInfo.InvariantCulture, message, numberOfAddresses)); result.Success = false; } else { party.ExternalId = Guid.NewGuid().ToString("B"); var response = this.AccountManager.AddParties(this.CurrentStorefront, customer, new List<Sitecore.Commerce.Entities.Party> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } else { var response = this.AccountManager.UpdateParties(this.CurrentStorefront, customer, new List<Sitecore.Commerce.Entities.Party> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } return Json(result, JsonRequestBehavior.AllowGet); } catch (Exception e) { CommerceLog.Current.Error("AddressModify", this, e); return Json(new BaseJsonResult("AddressModify", e), JsonRequestBehavior.AllowGet); } }
/// <summary> /// Translates the custom party. /// </summary> /// <param name="party">The party.</param> /// <param name="profile">The profile.</param> private void TranslateCustomParty(RefSFModels.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(RefSFModels.CommerceParty party, CommerceServer.Core.Runtime.Profiles.Profile profile) { }
/// <summary> /// To the party. /// </summary> /// <param name="item">The item.</param> /// <returns>A commecre party instance is returned.</returns> public static CommerceParty ToParty(this PartyInputModelItem item) { var party = new CommerceParty { Address1 = item.Address1, City = item.City, Country = item.Country, ExternalId = item.ExternalId, Name = item.Name, PartyId = item.PartyId, State = item.State, ZipPostalCode = item.ZipPostalCode }; return party; }
/// <summary> /// To the party. /// </summary> /// <param name="item">The item.</param> /// <returns>The CommerceParty instance.</returns> public static Party ToNewShippingParty(this PartyInputModelItem item) { var party = new CommerceParty { Address1 = item.Address1, City = item.City, Country = item.Country, ExternalId = string.IsNullOrWhiteSpace(item.PartyId) || item.PartyId == "0" ? Guid.NewGuid().ToString() : item.PartyId, Name = string.Format(CultureInfo.InvariantCulture, "{0}{1}", CommerceServerStorefrontConstants.CartConstants.ShippingAddressNamePrefix, item.Name), PartyId = item.PartyId, State = item.State, ZipPostalCode = item.ZipPostalCode }; return party; }
/// <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, RefSFModels.CommerceParty party) { }
/// <summary> /// Translates to commerce party. /// </summary> /// <param name="profile">The profile.</param> /// <param name="party">The party.</param> protected virtual void TranslateToCommerceParty(CommerceServer.Core.Runtime.Profiles.Profile profile, RefSFModels.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); }
public JsonResult AddressModify(PartyInputModelItem model) { try { Assert.ArgumentNotNull(model, "model"); var validationResult = new BaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var addresses = new List <CSFConnectModels.CommerceParty>(); var userResponse = this.AccountManager.GetUser(Context.User.Name); var result = new AddressListItemJsonResult(userResponse.ServiceProviderResult); if (userResponse.ServiceProviderResult.Success && userResponse.Result != null) { var commerceUser = userResponse.Result; var customer = new CommerceCustomer { ExternalId = commerceUser.ExternalId }; var party = new CSFConnectModels.CommerceParty { ExternalId = model.ExternalId, Name = model.Name, Address1 = model.Address1, City = model.City, Country = model.Country, State = model.State, ZipPostalCode = model.ZipPostalCode, PartyId = model.PartyId, IsPrimary = model.IsPrimary }; if (string.IsNullOrEmpty(party.ExternalId)) { // Verify we have not reached the maximum number of addresses supported. int numberOfAddresses = this.AllAddresses(result).Count; if (numberOfAddresses >= StorefrontManager.CurrentStorefront.MaxNumberOfAddresses) { var message = StorefrontManager.GetSystemMessage("MaxAddresseLimitReached"); result.Errors.Add(string.Format(CultureInfo.InvariantCulture, message, numberOfAddresses)); result.Success = false; } else { party.ExternalId = Guid.NewGuid().ToString("B"); var response = this.AccountManager.AddParties(this.CurrentStorefront, customer, new List <Sitecore.Commerce.Entities.Party> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } else { var response = this.AccountManager.UpdateParties(this.CurrentStorefront, customer, new List <Sitecore.Commerce.Entities.Party> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { CommerceLog.Current.Error("AddressModify", this, e); return(Json(new BaseJsonResult("AddressModify", e), JsonRequestBehavior.AllowGet)); } }