コード例 #1
0
        /// <summary>
        /// Initilaizes the specified shipping method per item.
        /// </summary>
        /// <param name="shippingMethodPerItem">The shipping method per item.</param>
        public virtual void Initialize(ShippingMethodPerItem shippingMethodPerItem)
        {
            if (shippingMethodPerItem == null)
            {
                return;
            }

            this.LineId = shippingMethodPerItem.LineId;

            if (shippingMethodPerItem.ShippingMethods != null && shippingMethodPerItem.ShippingMethods.Any())
            {
                var shippingMethodList = new List <ShippingMethodBaseJsonResult>();

                foreach (var shippingMethod in shippingMethodPerItem.ShippingMethods)
                {
                    var jsonResult = CommerceTypeLoader.CreateInstance <ShippingMethodBaseJsonResult>();

                    jsonResult.Initialize(shippingMethod);
                    shippingMethodList.Add(jsonResult);
                }

                this.ShippingMethods = shippingMethodList;
            }
        }
コード例 #2
0
        public void Initialize(ShippingMethodPerItem shippingMethodPerItem)
        {
            if (shippingMethodPerItem == null)
            {
                return;
            }

            LineId = shippingMethodPerItem.LineId;

            if (shippingMethodPerItem.ShippingMethods != null && shippingMethodPerItem.ShippingMethods.Any())
            {
                var shippingMethodList = new List <ShippingMethodApiModel>();

                foreach (var shippingMethod in shippingMethodPerItem.ShippingMethods)
                {
                    var jsonResult = new ShippingMethodApiModel();

                    jsonResult.Initialize(shippingMethod);
                    shippingMethodList.Add(jsonResult);
                }

                ShippingMethods = shippingMethodList;
            }
        }
        /// <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 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);
                    }
                }
            }
        }
コード例 #4
0
        /// <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 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 shippingOptionTypesFolder = this.GetShippingOptionsTypeFolder();

            string query           = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", shippingOptionTypesFolder.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.TypeId, request.ShippingOption.ShippingOptionType.Value);
            Item   foundOptionType = shippingOptionTypesFolder.Database.SelectSingleItem(query);

            if (foundOptionType != null)
            {
                Item shippingOptionsItem = this.GetShippingOptionsItem();

                query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", shippingOptionsItem.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.FulfillmentOptionType, foundOptionType.ID);
                Item fulfillmentOptionItem = shippingOptionsItem.Database.SelectSingleItem(query);
                if (fulfillmentOptionItem != null)
                {
                    // Has methods?
                    if (fulfillmentOptionItem.HasChildren)
                    {
                        List <ShippingMethod> returnList = new List <ShippingMethod>();

                        foreach (Item fulfillmentMethodItem in fulfillmentOptionItem.GetChildren())
                        {
                            // Do we have a Commerce Server Method?
                            if (fulfillmentMethodItem.HasChildren)
                            {
                                Item   csMethod   = fulfillmentMethodItem.GetChildren()[0];
                                string csMethodId = csMethod[StorefrontConstants.KnownFieldNames.MethodId];
                                Assert.IsNotNullOrEmpty(csMethodId, string.Format(CultureInfo.InvariantCulture, "The CS Method of the {0} Fulfillment Method is empty.", fulfillmentMethodItem.Name));

                                ShippingMethod shippingMethod = this.EntityFactory.Create <ShippingMethod>("ShippingMethod");

                                this.TranslateShippingMethod(fulfillmentOptionItem, fulfillmentMethodItem, csMethodId, shippingMethod);

                                returnList.Add(shippingMethod);
                            }
                        }

                        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 Services.Orders.GetShippingMethodsRequest && result is GetShippingMethodsResult)
                        {
                            var obecRequest = (Services.Orders.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);
                            }
                        }
                    }
                }
            }
        }