예제 #1
0
        public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address)
        {
            TraceContext   trace  = WebTrace.GetTraceContext();
            ShippingResult RetVal = new ShippingResult();

            RetVal.Shippable = false;

            CommerceBuilder.Orders.Basket basket = ThisOrder.AcBasket;
            if (basket == null)
            {
                basket = AcHelper.GetAcBasket(ThisOrder.ShoppingCart, true);
                if (basket != null)
                {
                    basket.Package(false);
                }
                ThisOrder.AcBasket = basket;
            }

            if (basket == null || basket.Shipments.Count == 0)
            {
                return(RetVal);
            }

            ShipMethodCollection shipMethods = ThisOrder.AcShipMethods;

            if (shipMethods == null)
            {
                shipMethods             = ShipMethodDataSource.LoadForStore();
                ThisOrder.AcShipMethods = shipMethods;
            }

            if (shipMethods == null || shipMethods.Count == 0)
            {
                return(RetVal);
            }

            ShipMethod shipMethod;
            string     methodName   = "";
            int        shipMethodId = AcHelper.ExtractShipMethodId(ShipMethodName, out methodName);

            if (shipMethodId != 0)
            {
                shipMethod = AcHelper.FindShipMethod(shipMethods, shipMethodId);
            }
            else
            {
                shipMethod = AcHelper.FindShipMethod(shipMethods, methodName);
            }
            if (shipMethod == null)
            {
                return(RetVal);
            }

            CommerceBuilder.Users.Address acAddress = AcHelper.GetAnonAcAddress(basket.User, Address);
            if (!shipMethod.IsApplicableTo(acAddress))
            {
                return(RetVal);
            }

            ShipRateQuote rateQuote;

            //TODO : should assign a default ship rate
            RetVal.ShippingRate = 0;
            bool isValid = true;

            foreach (Orders.BasketShipment bshipment in basket.Shipments)
            {
                bshipment.SetAddress(acAddress);
                if (!bshipment.IsShipMethodApplicable(shipMethod))
                {
                    isValid = false;
                    break;
                }
                rateQuote = shipMethod.GetShipRateQuote(bshipment);
                if (rateQuote != null && rateQuote.TotalRate > 0)
                {
                    RetVal.ShippingRate += rateQuote.TotalRate;
                }
                else if (rateQuote == null)
                {
                    //this ship method is not applicable
                    isValid = false;
                    break;
                }
            }

            if (isValid)
            {
                RetVal.Shippable = true;
            }

            return(RetVal);
        }
예제 #2
0
        public static ShipMethod GetShipMethod(Basket basket)
        {
            bool       shipMethodNameFound = false;
            string     shipMethName;
            BasketItem sItem = basket.Items.Find(delegate(BasketItem item) { return(item.OrderItemType == OrderItemType.Shipping); });

            if (sItem == null)
            {
                shipMethName = "Unknown(GoogleCheckout)";
            }
            else
            {
                shipMethName        = sItem.Name;
                shipMethodNameFound = true;
            }

            ShipMethodCollection shipMethods = ShipMethodDataSource.LoadForStore();
            ShipMethod           shipMethod;
            string methodName   = "";
            int    shipMethodId = ExtractShipMethodId(shipMethName, out methodName);

            if (shipMethodId != 0)
            {
                shipMethod = FindShipMethod(shipMethods, shipMethodId);
            }
            else
            {
                shipMethod = FindShipMethod(shipMethods, methodName);
            }

            if (shipMethod == null && !shipMethName.Equals("Unknown(GoogleCheckout)"))
            {
                shipMethod = FindShipMethod(shipMethods, "Unknown(GoogleCheckout)");
            }

            if (shipMethod == null)
            {
                //create a new ship method
                shipMethod                = new ShipMethod();
                shipMethod.Name           = "Unknown(GoogleCheckout)";
                shipMethod.ShipMethodType = ShipMethodType.FlatRate;
                shipMethod.MinPurchase    = 999999;
                shipMethod.Save();
            }

            if (shipMethod.Name.Equals("Unknown(GoogleCheckout)"))
            {
                if (shipMethodNameFound)
                {
                    Logger.Warn(string.Format("Shipping method named '{0}' used by GoogleCheckout could not be matched to any shipping method in the store.", shipMethName));
                    Logger.Warn("Using 'Unknown(GoogleCheckout)' shipping method.");
                }
                else
                {
                    Logger.Warn("No shipping method found in the GoogleCheckout notification.");
                    Logger.Warn("Using 'Unknown(GoogleCheckout)' shipping method.");
                }
            }

            return(shipMethod);
        }