コード例 #1
0
ファイル: DeliveryOption.cs プロジェクト: lanekp/LovRubWeb
 public void Combine(DeliveryOptionCollection options)
 {
     foreach (DeliveryOption option  in options)
     {
         this.Add(option);
     }
 }
コード例 #2
0
        public override DeliveryOptionCollection GetDeliveryOptions(PackageInfo package, DeliveryRestrictions restrictions)
        {
            Database db = DatabaseFactory.CreateDatabase();
            string   sp = "CSK_Shipping_GetRates";

            if (restrictions == DeliveryRestrictions.Air)
            {
                sp = "CSK_Shipping_GetRates_Air";
            }
            else if (restrictions == DeliveryRestrictions.Freight || restrictions == DeliveryRestrictions.Ground)
            {
                sp = "CSK_Shipping_GetRates_Ground";
            }

            using (DbCommand cmd = db.GetStoredProcCommand(sp))
            {
                db.AddInParameter(cmd, "@weight", DbType.Decimal, package.Weight);
                IDataReader rdr = db.ExecuteReader(cmd);

                DeliveryOptionCollection coll = new DeliveryOptionCollection();
                coll.Load(rdr);
                rdr.Close();
                return(coll);
            }
        }
コード例 #3
0
        public override DeliveryOptionCollection GetDeliveryOptions(PackageInfo package)
        {
            HttpRequestHandler       http       = new HttpRequestHandler(_connectionUrl);
            string                   rateXml    = http.POST(rateRequest(package));
            DeliveryOptionCollection collection = UspsParseRates(rateXml);

            return(collection);
        }
コード例 #4
0
    void BindShipping()
    {
        PackageInfo package = new PackageInfo();

        package.FromZip         = SiteConfig.ShipFromZip;
        package.FromCountryCode = SiteConfig.ShipFromCountryCode;
        package.ToZip           = AddressEntry1.SelectedAddress.Zip;;
        package.ToCountryCode   = AddressEntry1.SelectedAddress.Country;
        package.Weight          = order.GetItemsWeight();
        package.Width           = Convert.ToInt16(order.GetTotalWidth());
        package.Height          = Convert.ToInt16(order.GetTotalHeight());
        package.Length          = Convert.ToInt16(order.GetMaxLength());
        package.DimensionUnit   = SiteConfig.DimensionUnit;
        package.PackagingBuffer = SiteConfig.ShipPackagingBuffer;
        //Create Dictionary args for future expansion options
        package.Args = new Dictionary <string, string>();

        Commerce.Providers.DeliveryOptionCollection options = Commerce.Providers.FulfillmentService.GetOptions(package);
        radShipChoices.DataSource     = options;
        radShipChoices.DataTextField  = "Service";
        radShipChoices.DataValueField = "Rate";
        radShipChoices.DataBind();
        radShipChoices.SelectedIndex = 0;

        //check the shipping incentive
        decimal dShipping = decimal.Parse(radShipChoices.SelectedValue);
        //determine if discount is used
        decimal shipDiscount = 0;
        bool    haveDiscount = false;

        //localize it using the C formatter for local currency
        double dRate = 0;

        foreach (ListItem l in radShipChoices.Items)
        {
            decimal dShipCurrent = decimal.Parse(l.Value);

            //the discount is given as a percent, so divide it
            //by 100 to get the rate
            decimal discountRate = shipDiscount / 100;

            if (haveDiscount)
            {
                //apply it
                decimal dDiscountAmount  = dShipCurrent * discountRate;
                decimal dDiscountedPrice = dShipCurrent - dDiscountAmount;

                l.Value = dDiscountedPrice.ToString();
                l.Text += ": " + dDiscountedPrice.ToString("C") + " (discounted " + dDiscountAmount.ToString("C") + ")";
            }
            else
            {
                l.Text += ": " + dShipCurrent.ToString("C");
            }
        }
    }
コード例 #5
0
        public static DeliveryOptionCollection GetOptions(PackageInfo package)
        {
            LoadProviders();
            DeliveryOptionCollection options = new DeliveryOptionCollection();

            //if there are no restrictions, hit every provider and return the collection
            foreach (FulfillmentProvider provider in _providers)
            {
                options.Combine(provider.GetDeliveryOptions(package));
            }
            return(options);
        }
コード例 #6
0
        public override DeliveryOptionCollection GetDeliveryOptions(PackageInfo package, DeliveryRestrictions restrictions)
        {
            //TODO: I need to put a little more thought into the restrictions
            if (restrictions == DeliveryRestrictions.Download)
            {
                throw new Exception("Shipping Error: This item is download only.");
            }
            _deliveryRestriction = restrictions;
            HttpRequestHandler       http       = new HttpRequestHandler(_connectionUrl);
            string                   rateXml    = http.POST(rateRequest(package));
            DeliveryOptionCollection collection = UspsParseRates(rateXml);

            return(collection);
        }
コード例 #7
0
        public override DeliveryOptionCollection GetDeliveryOptions(PackageInfo package)
        {
            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand cmd = db.GetStoredProcCommand("CSK_Shipping_GetRates"))
            {
                db.AddInParameter(cmd, "@weight", DbType.Decimal, package.Weight);
                IDataReader rdr = db.ExecuteReader(cmd);

                DeliveryOptionCollection coll = new DeliveryOptionCollection();
                coll.Load(rdr);
                rdr.Close();
                return(coll);
            }
        }
コード例 #8
0
    void BindShipping(PackageInfo package)
    {
        //IDataReader rdr = Commerce.Providers.ShippingService.GetShippingChoices(package);

        Commerce.Providers.DeliveryOptionCollection options = Commerce.Providers.FulfillmentService.GetOptions(package);
        radShipChoices.DataSource     = options;
        radShipChoices.DataTextField  = "Service";
        radShipChoices.DataValueField = "Rate";
        radShipChoices.DataBind();
        radShipChoices.SelectedIndex = 0;

        //localize it using the C formatter for local currency
        decimal dRate = 0;

        foreach (ListItem l in radShipChoices.Items)
        {
            dRate   = decimal.Parse(l.Value);
            l.Text += ": " + dRate.ToString("C");
        }

        //set the Profile Shipping Bits
        Profile.CurrentOrderShipping       = decimal.Parse(radShipChoices.SelectedValue);
        Profile.CurrentOrderShippingMethod = radShipChoices.SelectedItem.Text;
    }
コード例 #9
0
        private DeliveryOptionCollection UspsParseRates(string response)
        {
            DeliveryOptionCollection optionCollection = new DeliveryOptionCollection();
            StringReader             sr = new StringReader(response);
            XmlTextReader            tr = new XmlTextReader(sr);

            try
            {
                while (tr.Read())
                {
                    if ((tr.Name == "Error") && (tr.NodeType == XmlNodeType.Element))
                    {
                        string errorText = "";
                        while (tr.Read())
                        {
                            if ((tr.Name == "HelpContext") && (tr.NodeType == XmlNodeType.Element))
                            {
                                errorText += "USPS Help Context: " + tr.ReadString() + ", ";
                            }
                            if ((tr.Name == "Description") && (tr.NodeType == XmlNodeType.Element))
                            {
                                errorText += "Error Desc: " + tr.ReadString();
                            }
                        }
                        throw new ProviderException("USPS Error returned: " + errorText);
                    }
                    if ((tr.Name == "Postage") && (tr.NodeType == XmlNodeType.Element))
                    {
                        string serviceCode = "";
                        string postalRate  = "";
                        while (tr.Read())
                        {
                            if ((tr.Name == "MailService") && (tr.NodeType == XmlNodeType.Element))
                            {
                                serviceCode = tr.ReadString();
                                tr.ReadEndElement();
                                if ((tr.Name == "MailService") && (tr.NodeType == XmlNodeType.EndElement))
                                {
                                    break;
                                }
                            }
                            if (((tr.Name == "Postage") && (tr.NodeType == XmlNodeType.EndElement)) || ((tr.Name == "Postage") && (tr.NodeType == XmlNodeType.Element)))
                            {
                                break;
                            }
                            if ((tr.Name == "Rate") && (tr.NodeType == XmlNodeType.Element))
                            {
                                postalRate = tr.ReadString();
                                tr.ReadEndElement();
                                if ((tr.Name == "Rate") && (tr.NodeType == XmlNodeType.EndElement))
                                {
                                    break;
                                }
                            }
                        }
                        string  service = GetServiceName(serviceCode);
                        decimal rate    = Convert.ToDecimal(postalRate);
                        if (!String.IsNullOrEmpty(_uspsAdditionalHandlingCharge))
                        {
                            decimal additionalHandling = Convert.ToDecimal(_uspsAdditionalHandlingCharge);
                            rate += additionalHandling;
                        }
                        //Weed out unwanted or unkown service rates
                        if (service.ToUpper() != "UNKNOWN")
                        {
                            DeliveryOption option = new DeliveryOption();
                            option.Rate    = rate;
                            option.Service = service;
                            optionCollection.Add(option);
                        }
                    }
                }
                sr.Dispose();
                return(optionCollection);
            }
            catch
            {
                throw;
            }
            finally
            {
                sr.Close();
                tr.Close();
            }
        }