Example #1
0
        private bool isSellableItemWeightWithInPolicyLimit(
            ItemSpecificationsComponent itemSpec,
            ShipEnginePolicy localPolicy,
            GlobalPhysicalFulfillmentPolicy globalPolicy)
        {
            if (itemSpec == null ||
                string.IsNullOrWhiteSpace(itemSpec.WeightUnitOfMeasure) ||
                globalPolicy == null ||
                string.IsNullOrWhiteSpace(globalPolicy.WeightUnits))
            {
                return(true);
            }

            var globalWeightUnits = localPolicy.StringToWeightUnit(globalPolicy.WeightUnits);

            var itemWeightUnits = localPolicy.StringToWeightUnit(itemSpec.WeightUnitOfMeasure);

            return(ToGrams(itemWeightUnits, itemSpec.Weight) <= ToGrams(globalWeightUnits, (double)globalPolicy.MaxShippingWeight));
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task <string> Run(string arg, CommercePipelineExecutionContext context)
        {
            // a new fulfilment policy based on result from web service.
            var fulfillmentPolicy = new GlobalPhysicalFulfillmentPolicy
            {
                PolicyId                   = typeof(GlobalPhysicalFulfillmentPolicy).Name,
                MaxShippingWeight          = 50,
                MeasurementUnits           = "Inches",
                WeightUnits                = "Lbs",
                DefaultCartFulfillmentFee  = new Money("USD", 14M),
                DefaultCartFulfillmentFees =
                    new List <Money>()
                {
                    new Money("USD", 24M), new Money("CAD", 24M)
                },
                DefaultItemFulfillmentFee  = new Money("USD", 34M),
                DefaultItemFulfillmentFees =
                    new List <Money>()
                {
                    new Money("USD", 44M), new Money("CAD", 44M)
                },
                FulfillmentFees =
                    new List <FulfillmentFee>
                {
                    new FulfillmentFee
                    {
                        Name = "Fedex 2 Day",
                        Fee  = new Money("USD", 11)
                    },
                    new FulfillmentFee
                    {
                        Name = "Fedex Express Saver",
                        Fee  = new Money("USD", 12)
                    },
                    new FulfillmentFee
                    {
                        Name = "Priority Overnight",
                        Fee  = new Money("USD", 13)
                    },
                    new FulfillmentFee
                    {
                        Name = " Standard Overnight",
                        Fee  = new Money("USD", 14)
                    },
                    new FulfillmentFee
                    {
                        Name = "Fedex 2 Day",
                        Fee  = new Money("CAD", 11)
                    },
                    new FulfillmentFee
                    {
                        Name = "Fedex Express Saver",
                        Fee  = new Money("CAD", 12)
                    },
                    new FulfillmentFee
                    {
                        Name = "Priority Overnight",
                        Fee  = new Money("CAD", 13)
                    },
                    new FulfillmentFee
                    {
                        Name = " Standard Overnight",
                        Fee  = new Money("CAD", 14)
                    }
                }
            };

            var existingEnvironment = this._findEntityPipeline.Run(new FindEntityArgument(typeof(CommerceEnvironment), "Entity-CommerceEnvironment-HabitatAuthoring"), context).Result as CommerceEnvironment;

            if (existingEnvironment != null)
            {
                try
                {
                    var pos = 0;
                    foreach (var environmentPolicy in existingEnvironment.Policies)
                    {
                        if (environmentPolicy.PolicyId == typeof(GlobalPhysicalFulfillmentPolicy).Name)
                        {
                            break;
                        }
                        pos++;
                    }

                    if (pos > 0)
                    {
                        existingEnvironment.Policies.RemoveAt(pos);
                        existingEnvironment.Policies.Add(fulfillmentPolicy);
                        existingEnvironment.IsPersisted = true;
                    }
                }
                catch (Exception ex)
                {
                    context.Logger.LogError($"Exception in ChangeFulfillmentOptionsBlock - {ex}");
                }
            }

            try
            {
                this._persistEntityPipeline.Run(new PersistEntityArgument(existingEnvironment), context).Wait();
            }
            catch (System.Exception ex)
            {
                context.Logger.LogError($"Exception in ChangeFulfillmentOptionsBlock - {ex}");
            }

            return(Task.FromResult(arg));
        }