Exemplo n.º 1
0
        protected ShippingMethods GetRates()
        {
            decimal ShippingHandlingExtraFee = AppLogic.AppConfigNativeDecimal("ShippingHandlingExtraFee");
            bool    IsShipSeparately         = GetProductIsShipSeparately(ProductID);

            RTShipping realTimeShipping = new RTShipping();

            Decimal MarkupPercent = AppLogic.AppConfigUSDecimal("RTShipping.MarkupPercent");

            // Set shipment info
            decimal ProductWeight = GetVariantWeight(VariantID);
            decimal ProductPrice  = AppLogic.GetVariantPrice(VariantID);

            realTimeShipping.ShipmentWeight = ProductWeight * Quantity;
            if (realTimeShipping.ShipmentWeight == System.Decimal.Zero)
            {
                realTimeShipping.ShipmentWeight = AppLogic.AppConfigUSDecimal("RTShipping.DefaultItemWeight"); // force a default.
            }


            //Create Shipments Collection
            Shipments shipments = new Shipments();

            // Create Packages Collection
            Packages shipment = new Packages();

            int PackageID = 1;

            shipments = new Shipments();

            shipment = new Packages();

            // Set pickup type
            shipment.PickupType = AppLogic.AppConfig("RTShipping.UPS.UPSPickupType"); // RTShipping.PickupTypes.UPSCustomerCounter.ToString();
            if (AppLogic.AppConfig("RTShipping.UPS.UPSPickupType").Length == 0)
            {
                shipment.PickupType = RTShipping.PickupTypes.UPSCustomerCounter.ToString();
            }

            // Set destination address of this package group:
            Address sa = new Address();

            sa.LoadFromDB(ThisCustomer.PrimaryShippingAddressID);
            shipment.DestinationCity                  = sa.City;
            shipment.DestinationStateProvince         = sa.State;
            shipment.DestinationZipPostalCode         = sa.Zip;
            shipment.DestinationCountryCode           = AppLogic.GetCountryTwoLetterISOCode(sa.Country);
            shipment.DestinationResidenceType         = sa.ResidenceType;
            realTimeShipping.DestinationResidenceType = shipment.DestinationResidenceType;

            // now override them with what is passed in here:
            shipment.DestinationCountryCode   = AppLogic.GetCountryTwoLetterISOCode(Country);
            shipment.DestinationStateProvince = State;
            shipment.DestinationZipPostalCode = PostalCode;

            if (IsShipSeparately)
            {
                for (int i = 1; i <= Quantity; i++)
                {
                    Package p = new Package();
                    p.PackageId = PackageID;
                    PackageID   = PackageID + 1;
                    String Dimensions = String.Empty; // not supported here
                    p.Weight = ProductWeight;
                    if (p.Weight == System.Decimal.Zero)
                    {
                        p.Weight = 0.5M; // must have SOMETHING to use!
                    }
                    p.Weight      += AppLogic.AppConfigUSDecimal("RTShipping.PackageExtraWeight");
                    p.Insured      = AppLogic.AppConfigBool("RTShipping.Insured");
                    p.InsuredValue = ProductPrice;
                    shipment.AddPackage(p);
                    realTimeShipping.ShipmentValue += ProductPrice;
                    p = null;
                }
            }
            else
            {
                Package p = new Package();
                p.PackageId = PackageID;
                PackageID   = PackageID + 1;
                String Dimensions = String.Empty;
                p.Weight = ProductWeight * Quantity;
                if (p.Weight == System.Decimal.Zero)
                {
                    p.Weight = 0.5M; // must have SOMETHING to use!
                }
                p.Weight      += AppLogic.AppConfigUSDecimal("RTShipping.PackageExtraWeight");
                p.Insured      = AppLogic.AppConfigBool("RTShipping.Insured");
                p.InsuredValue = ProductPrice * Quantity;
                shipment.AddPackage(p);
                p = null;
                realTimeShipping.ShipmentValue = ProductPrice * Quantity;
            }

            shipments.AddPackages(shipment);

            // Get carriers
            string carriers = String.Empty;

            if (shipment.DestinationCountryCode.Equals("US", StringComparison.InvariantCultureIgnoreCase))
            {
                carriers = AppLogic.AppConfig("RTshipping.DomesticCarriers");
            }
            else
            {
                carriers = AppLogic.AppConfig("RTshipping.InternationalCarriers");
            }
            if (carriers.Length == 0)
            {
                carriers = AppLogic.AppConfig("RTShipping.ActiveCarrier");
            }


            // Get result type
            RTShipping.ResultType format = RTShipping.ResultType.CollectionList;
            String  RTShipRequest        = String.Empty;
            String  RTShipResponse       = String.Empty;
            decimal ShippingTaxRate      = System.Decimal.Zero; // NOT supported here

            return((ShippingMethods)realTimeShipping.GetRates(shipments, carriers, format, "ShippingMethod", "ShippingMethod", ShippingTaxRate, out RTShipRequest, out RTShipResponse, ShippingHandlingExtraFee, (decimal)MarkupPercent, realTimeShipping.ShipmentValue));
        }