public override void Process()

in src/Feature/Cart/code/Pipelines/Shipping/GetShippingMethods.cs [49:124]


        public override void Process(Commerce.Pipelines.ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentCondition(args.Request is CommerceGetShippingMethodsRequest, "args.Request", "args.Request is CommerceGetShippingMethodsRequest");
            Assert.ArgumentCondition(args.Result is GetShippingMethodsResult, "args.Result", "args.Result is GetShippingMethodsResult");

            var request = (CommerceGetShippingMethodsRequest)args.Request;
            var result = (GetShippingMethodsResult)args.Result;

            Assert.ArgumentNotNullOrEmpty(request.Language, "request.Language");

            if (request.ShippingOption.ShippingOptionType == null)
            {
                base.Process(args);
                return;
            }

            Item shippingOptionsItem = this.GetShippingOptionsItem();

            string query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", shippingOptionsItem.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.ShippingOptionValue, request.ShippingOption.ShippingOptionType.Value);
            Item foundOption = shippingOptionsItem.Database.SelectSingleItem(query);
            if (foundOption != null)
            {
                string shippingMethodsIds = foundOption[CommerceServerStorefrontConstants.KnownFieldNames.CommerceServerShippingMethods];
                if (!string.IsNullOrWhiteSpace(shippingMethodsIds))
                {
                    base.Process(args);
                    if (result.Success)
                    {
                        List<ShippingMethod> currentList = new List<ShippingMethod>(result.ShippingMethods);
                        List<ShippingMethod> returnList = new List<ShippingMethod>();

                        string[] ids = shippingMethodsIds.Split('|');
                        foreach (string id in ids)
                        {
                            string trimmedId = id.Trim();

                            var found2 = currentList.Find(o => o.ExternalId.Equals(trimmedId, StringComparison.OrdinalIgnoreCase));
                            ShippingMethod found = currentList.Find(o => o.ExternalId.Equals(trimmedId, StringComparison.OrdinalIgnoreCase)) as ShippingMethod;
                            if (found != null)
                            {
                                returnList.Add(found);
                            }
                        }

                        result.ShippingMethods = new System.Collections.ObjectModel.ReadOnlyCollection<ShippingMethod>(returnList);
                    }
                }

                // We need to do this type casting for now until the base OBEC classes support the additional properties.  Setting the shipping
                // methods calls this pipeline processor for validation purposes (call is made by CS integration) and we must allow to be called using
                // the original CS integration classes.
                if (request is Sitecore.Foundation.CommerceServer.Helpers.GetShippingMethodsRequest && result is GetShippingMethodsResult)
                {
                    var obecRequest = (Sitecore.Foundation.CommerceServer.Helpers.GetShippingMethodsRequest)request;
                    var obecResult = (GetShippingMethodsResult)result;

                    if (obecRequest.Lines != null && obecRequest.Lines.Any())
                    {
                        var shippingMethodPerItemList = new List<ShippingMethodPerItem>();

                        foreach (var line in obecRequest.Lines)
                        {
                            var shippingMethodPerItem = new ShippingMethodPerItem();

                            shippingMethodPerItem.LineId = line.ExternalCartLineId;
                            shippingMethodPerItem.ShippingMethods = result.ShippingMethods;

                            shippingMethodPerItemList.Add(shippingMethodPerItem);
                        }

                        obecResult.ShippingMethodsPerItem = new System.Collections.ObjectModel.ReadOnlyCollection<ShippingMethodPerItem>(shippingMethodPerItemList);
                    }
                }
            }
        }