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();
        }
Example #2
0
        public override void Process(ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.Request");
            Assert.ArgumentNotNull(args.Result, "args.Result");
            Assert.IsTrue((bool)(args.Request is SubmitVisitorOrderRequest), "args.Request is SubmitVisitorOrderRequest");
            Assert.IsTrue((bool)(args.Result is SubmitVisitorOrderResult), "args.Result is SubmitVisitorOrderResult");

            SubmitVisitorOrderRequest request = (SubmitVisitorOrderRequest)args.Request;
            SubmitVisitorOrderResult  result  = (SubmitVisitorOrderResult)args.Result;
            CartPipelineContext       context = CartPipelineContext.Get(request.RequestContext);

            Assert.IsNotNull(context, "cartContext");

            if (((context.Basket != null) && !context.HasBasketErrors) && result.Success)
            {
                foreach (OrderForm orderForm in context.Basket.OrderForms)
                {
                    foreach (LineItem lineItem in orderForm.LineItems)
                    {
                        var cartLine = request.Cart.Lines.FirstOrDefault(l => l.ExternalCartLineId.Equals(lineItem.LineItemId.ToString("B"), StringComparison.OrdinalIgnoreCase));
                        if (cartLine == null)
                        {
                            continue;
                        }

                        // Store the image as a string since a dictionary is not serializable and causes problems in C&OM.
                        StringBuilder imageList = new StringBuilder();
                        foreach (MediaItem image in ((CustomCommerceCartLine)cartLine).Images)
                        {
                            if (image != null)
                            {
                                if (imageList.Length > 0)
                                {
                                    imageList.Append("|");
                                }

                                imageList.Append(image.ID.ToString());
                                imageList.Append(",");
                                imageList.Append(image.MediaPath);
                            }
                        }

                        lineItem["Images"] = imageList.ToString();
                    }
                }

                PurchaseOrder orderGroup = context.Basket.SaveAsOrder();
                TranslateOrderGroupToEntityRequest request2 = new TranslateOrderGroupToEntityRequest(context.UserId, context.ShopName, orderGroup);
                TranslateOrderGroupToEntityResult  result2  = PipelineUtility.RunCommerceConnectPipeline <TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>("translate.orderGroupToEntity", request2);
                result.Order = result2.Cart as Order;
            }
        }
        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);
        }
Example #4
0
        /// <summary>
        /// Adds the party.
        /// </summary>
        /// <param name="party">The party.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="cartContext">The cart context.</param>
        /// <returns>
        /// The commerce party that was added.
        /// </returns>
        protected virtual ConnectOrderModels.CommerceParty AddParty(Party party, string entityName, CartPipelineContext cartContext)
        {
            OrderAddress destinationAddress = CommerceTypeLoader.CreateInstance <OrderAddress>(new object[] { this.GetPartyName(party), party.ExternalId });

            RefSFArguments.TranslateEntityToOrderAddressRequest translateRequest = new RefSFArguments.TranslateEntityToOrderAddressRequest(party, destinationAddress);

            var translateResult = PipelineUtility.RunCommerceConnectPipeline <RefSFArguments.TranslateEntityToOrderAddressRequest, TranslateEntityToOrderAddressResult>(PipelineNames.TranslateEntityToOrderAddress, translateRequest);

            OrderAddress newOrderAddress = translateResult.Address;

            cartContext.Basket.Addresses.Add(newOrderAddress);

            ConnectOrderModels.CommerceParty translatedParty = this.EntityFactory.Create <ConnectOrderModels.CommerceParty>(entityName);
            Assert.ArgumentNotNull(translatedParty, "translatedParty");

            RefSFArguments.TranslateOrderAddressToEntityRequest translateOrderAddressRequest = new RefSFArguments.TranslateOrderAddressToEntityRequest(newOrderAddress, translatedParty);
            PipelineUtility.RunCommerceConnectPipeline <RefSFArguments.TranslateOrderAddressToEntityRequest, CommerceResult>(PipelineNames.TranslateOrderAddressToEntity, translateOrderAddressRequest);

            return(translatedParty);
        }
Example #5
0
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(Sitecore.Commerce.Pipelines.ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.request");

            RemovePartiesRequest request = (RemovePartiesRequest)args.Request;
            RemovePartiesResult  result  = (RemovePartiesResult)args.Result;

            var cartContext = CartPipelineContext.Get(request.RequestContext);

            Assert.IsNotNull(cartContext, "cartContext");

            List <Party> partiesRemoved = new List <Party>();

            if (cartContext.Basket != null)
            {
                foreach (Party party in request.Parties)
                {
                    if (party != null)
                    {
                        Assert.ArgumentNotNullOrEmpty(party.ExternalId, "party.ExternalId");

                        OrderAddress orderAddress = cartContext.Basket.Addresses[party.ExternalId];
                        if (orderAddress != null)
                        {
                            cartContext.Basket.Addresses.Remove(orderAddress);

                            partiesRemoved.Add(party);
                        }
                    }
                }
            }

            result.Parties = partiesRemoved;

            // Needed by the RunSaveCart CommerceConnect pipeline.
            var translateCartRequest = new TranslateOrderGroupToEntityRequest(cartContext.UserId, cartContext.ShopName, cartContext.Basket);
            var translateCartResult  = PipelineUtility.RunCommerceConnectPipeline <TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>(PipelineNames.TranslateOrderGroupToEntity, translateCartRequest);

            result.Cart = translateCartResult.Cart;
        }
Example #6
0
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(Sitecore.Commerce.Pipelines.ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.request");

            AddPartiesRequest request = (AddPartiesRequest)args.Request;
            AddPartiesResult  result  = (AddPartiesResult)args.Result;

            var cartContext = CartPipelineContext.Get(request.RequestContext);

            Assert.IsNotNull(cartContext, "cartContext");

            List <Party> partiesAdded = new List <Party>();

            if (cartContext.Basket != null)
            {
                foreach (Party party in request.Parties)
                {
                    Party newParty;

                    if (party == null)
                    {
                        continue;
                    }

                    newParty = this.ProcessParty(party, cartContext);

                    partiesAdded.Add(newParty);
                }
            }

            result.Parties = partiesAdded;

            // Needed by the RunSaveCart CommerceConnect pipeline.
            var translateCartRequest = new TranslateOrderGroupToEntityRequest(cartContext.UserId, cartContext.ShopName, cartContext.Basket);
            var translateCartResult  = PipelineUtility.RunCommerceConnectPipeline <TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>(PipelineNames.TranslateOrderGroupToEntity, translateCartRequest);

            result.Cart = translateCartResult.Cart;
        }
Example #7
0
        /// <summary>
        /// Adds the user profile address.
        /// </summary>
        /// <param name="party">The party.</param>
        /// <param name="cartContext">The cart context.</param>
        /// <returns>The commerce party that was added.</returns>
        protected virtual ConnectOrderModels.CommerceParty AddUserProfileAddress(ConnectOrderModels.CommerceParty party, CartPipelineContext cartContext)
        {
            Assert.IsTrue(party.UserProfileAddressId != Guid.Empty, "party.UserProfileAddressId != Guid.Empty");
            Assert.IsNotNullOrEmpty(party.Name, "party.Name");

            var repository = this.GetProfileRepository();

            Profile addressProfile = repository.GetProfile("Address", party.UserProfileAddressId.ToString("B"));

            Assert.IsNotNull(addressProfile, string.Format(CultureInfo.InvariantCulture, "An invalid address profile was provided: {0}", party.UserProfileAddressId.ToString("B")));

            OrderAddress newOrderAddress = CommerceTypeLoader.CreateInstance <OrderAddress>(new object[] { party.Name, addressProfile });

            cartContext.Basket.Addresses.Add(newOrderAddress);

            ConnectOrderModels.CommerceParty translatedParty = this.EntityFactory.Create <ConnectOrderModels.CommerceParty>("Party");
            Assert.ArgumentNotNull(translatedParty, "translatedParty");

            var translateOrderAddressRequest = new RefSFArguments.TranslateOrderAddressToEntityRequest(newOrderAddress, translatedParty);

            PipelineUtility.RunCommerceConnectPipeline <RefSFArguments.TranslateOrderAddressToEntityRequest, CommerceResult>(PipelineNames.TranslateOrderAddressToEntity, translateOrderAddressRequest);

            return(translatedParty);
        }
Example #8
0
        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();
            }
        }
Example #9
0
        /// <summary>
        /// Translates the address.
        /// </summary>
        /// <param name="sourceAddress">The source address.</param>
        /// <param name="destinationParty">The destination party.</param>
        protected virtual void TranslateAddress(OrderAddress sourceAddress, EmailParty destinationParty)
        {
            TranslateOrderAddressToEntityRequest request = new TranslateOrderAddressToEntityRequest(sourceAddress, destinationParty);

            PipelineUtility.RunCommerceConnectPipeline <TranslateOrderAddressToEntityRequest, CommerceResult>(PipelineNames.TranslateOrderAddressToEntity, request);
        }
Example #10
0
        /// <summary>
        /// Translates the address.
        /// </summary>
        /// <param name="sourceAddress">The source address.</param>
        /// <param name="destinationParty">The destination party.</param>
        protected override void TranslateAddress(OrderAddress sourceAddress, Commerce.Connect.CommerceServer.Orders.Models.CommerceParty destinationParty)
        {
            TranslateOrderAddressToEntityRequest request = new TranslateOrderAddressToEntityRequest(sourceAddress, destinationParty);

            PipelineUtility.RunCommerceConnectPipeline <TranslateOrderAddressToEntityRequest, CommerceResult>(PipelineNames.TranslateOrderAddressToEntity, request);
        }
 /// <summary>
 /// Translates the address.
 /// </summary>
 /// <param name="sourceAddress">The source address.</param>
 /// <param name="destinationParty">The destination party.</param>
 protected virtual void TranslateAddress(CommerceServer.Core.Runtime.Orders.OrderAddress sourceAddress, EmailParty destinationParty)
 {
     RefSFArguments.TranslateOrderAddressToEntityRequest request = new RefSFArguments.TranslateOrderAddressToEntityRequest(sourceAddress, destinationParty);
     PipelineUtility.RunCommerceConnectPipeline <RefSFArguments.TranslateOrderAddressToEntityRequest, CommerceResult>(PipelineNames.TranslateOrderAddressToEntity, request);
 }