Narrowing Down USPS shipping methods in 1.5

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 14 años
shokokoo wrote:


Sorry if it wasn't clear how to add new services to skip. I've changed the code to include additional services and to make it work similar to the domestic rates (uncomment service names to have their rates displayed -ensure at least one is uncommented).

Use the following instead of the previous code block (the services you wanted are already uncommented):[code]

        //case "Global Express Guaranteed (GXG)":
        //case "Global Express Guaranteed Non-Document Rectangular":
        //case "Global Express Guaranteed Non-Document Non-Rectangular":
        //case "USPS GXG Envelopes":
        //case "Express Mail International Flat Rate Envelope":
        //case "Priority Mail International":
        //case "Priority Mail International Large Flat Rate Box":
        //case "Priority Mail International Medium Flat Rate Box":
        //case "Priority Mail International Small Flat Rate Box":
        //case "First-Class Mail International Large Envelope":

        case "Express Mail International":
        case "Priority Mail International Flat Rate Envelope":
        case "First-Class Mail International Package":
            break;
        default:
            continue;


This solutions works good now only displays the options I need. Thanks mb. But this fix seems to break the domestic (US) shipping options. now when I select a domestic shipping address it displays the following error
Shipping options could not be loaded
Hace 14 años
One more thing. Is there a way to a description under each shipping option i.e. (in bold)
USPS Express Mail International
(3 - 5 business days)

Thanks
Hace 14 años
shokokoo wrote:

This solutions works good now only displays the options I need. Thanks mb. But this fix seems to break the domestic (US) shipping options. now when I select a domestic shipping address it displays the following error
Shipping options could not be loaded


Update the code to the following (only added the if statement to apply filtering to the services if they are not domestic):

    if (isDomestic == false)
    {    
        switch (serviceCode)
        {
            //case "Global Express Guaranteed (GXG)":
            //case "Global Express Guaranteed Non-Document Rectangular":
            //case "Global Express Guaranteed Non-Document Non-Rectangular":
            //case "USPS GXG Envelopes":
            //case "Express Mail International Flat Rate Envelope":
            //case "Priority Mail International":
            //case "Priority Mail International Large Flat Rate Box":
            //case "Priority Mail International Medium Flat Rate Box":
            //case "Priority Mail International Small Flat Rate Box":
            //case "First-Class Mail International Large Envelope":

            case "Express Mail International":
            case "Priority Mail International Flat Rate Envelope":
            case "First-Class Mail International Package":
                break;
            default:
                continue;
        }
    }

.
Hace 14 años
Thanks that fixed the problem
Hace 14 años
shokokoo wrote:
One more thing. Is there a way to a description under each shipping option i.e. (in bold)
USPS Express Mail International
(3 - 5 business days)

Thanks


It can be done, but only international rate responses include the service commitments (time to deliver); the delivery times for domestic rates would have to be hard-coded in ParseResponse().

---

The following is the updated ParseResponse() method that includes service commitments for international and domestic USPS rates.

You can edit the delivery times as needed for domestic services and if you don't want to display a delivery time for a service, use serviceDescription = String.Empty; (as with "Library Mail").

The parenthesis are inserted, near the bottom of the method, with the line:
serviceDescription = String.Format("({0})", serviceDescription);.

private ShippingOptionCollection ParseResponse(string response, bool isDomestic, ref string error)
{
    var shippingOptions = new ShippingOptionCollection();

    string postageStr = isDomestic ? "Postage" : "Service";
    string mailServiceStr = isDomestic ? "MailService" : "SvcDescription";
    string rateStr = isDomestic ? "Rate" : "Postage";
    string svcCommitments = "SvcCommitments";

    using (var sr = new StringReader(response))
    using (var tr = new XmlTextReader(sr))
    {
        do
        {
            tr.Read();

            if ((tr.Name == "Error") && (tr.NodeType == XmlNodeType.Element))
            {
                string errorText = "";
                while (tr.Read())
                {
                    if ((tr.Name == "Description") && (tr.NodeType == XmlNodeType.Element))
                        errorText += "Error Desc: " + tr.ReadString();
                    if ((tr.Name == "HelpContext") && (tr.NodeType == XmlNodeType.Element))
                        errorText += "USPS Help Context: " + tr.ReadString() + ". ";
                }
                error = "USPS Error returned: " + errorText;
            }

            if ((tr.Name == postageStr) && (tr.NodeType == XmlNodeType.Element))
            {
                string serviceCode = string.Empty;
                string postalRate = string.Empty;
                string serviceDescription = string.Empty;

                do
                {

                    tr.Read();

                    if ((tr.Name == svcCommitments) && (tr.NodeType == XmlNodeType.Element))
                    {
                        serviceDescription = tr.ReadString();
                        serviceDescription = serviceDescription.Replace("Days", "Business Days");
                        //tr.ReadEndElement();
                        //if ((tr.Name == svcCommitments) && (tr.NodeType == XmlNodeType.EndElement))
                        //    break;
                    }

                    if ((tr.Name == mailServiceStr) && (tr.NodeType == XmlNodeType.Element))
                    {
                        serviceCode = tr.ReadString();
                        //tr.ReadEndElement();
                        //if ((tr.Name == mailServiceStr) && (tr.NodeType == XmlNodeType.EndElement))
                        //    break;
                    }

                    if ((tr.Name == rateStr) && (tr.NodeType == XmlNodeType.Element))
                    {
                        postalRate = tr.ReadString();
                        //tr.ReadEndElement();
                        //if ((tr.Name == rateStr) && (tr.NodeType == XmlNodeType.EndElement))
                        //    break;
                    }
                }
                while (!((tr.Name == postageStr) && (tr.NodeType == XmlNodeType.EndElement)));

                if (isDomestic == false)
                {
                    // Uncomment service names to display their rates (need at least one uncommented)
                    switch (serviceCode)
                    {
                        //case "Global Express Guaranteed (GXG)":
                        //case "Global Express Guaranteed Non-Document Rectangular":
                        //case "Global Express Guaranteed Non-Document Non-Rectangular":
                        //case "USPS GXG Envelopes":
                        //case "Express Mail International Flat Rate Envelope":
                        //case "Priority Mail International":
                        //case "Priority Mail International Large Flat Rate Box":
                        //case "Priority Mail International Medium Flat Rate Box":
                        //case "Priority Mail International Small Flat Rate Box":
                        //case "First-Class Mail International Large Envelope":
                        case "Express Mail International":
                        case "Priority Mail International Flat Rate Envelope":
                        case "First-Class Mail International Package":
                            break;
                        default:
                            continue;
                    }
                }
                else // manually set service commitments for domestic rates
                {
                    switch (serviceCode)
                    {
                        case "Express Mail Sunday/Holiday Guarantee":
                            serviceDescription = "1 - 2 Business Days";
                            break;
                        case "Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee":
                            serviceDescription = "1 - 2 Business Days";
                            break;
                        case "Express Mail Hold For Pickup":
                            serviceDescription = "1 - 2 Business Days";
                            break;
                        case "Express Mail Flat Rate Envelope Hold For Pickup":
                            serviceDescription = "1 - 2 Business Days";
                            break;
                        case "Express Mail":
                            serviceDescription = "1 - 2 Business Days";
                            break;
                        case "Express Mail Flat Rate Envelope":
                            serviceDescription = "1 - 2 Business Days";
                            break;
                        case "Priority Mail":
                            serviceDescription = "2 - 3 Business Days";
                            break;
                        case "Priority Mail Flat Rate Envelope":
                            serviceDescription = "2 - 3 Business Days";
                            break;
                        case "Priority Mail Small Flat Rate Box":
                            serviceDescription = "2 - 3 Business Days";
                            break;
                        case "Priority Mail Medium Flat Rate Box":
                            serviceDescription = "2 - 3 Business Days";
                            break;
                        case "Priority Mail Large Flat Rate Box":
                            serviceDescription = "2 - 3 Business Days";
                            break;
                        case "Parcel Post":
                            serviceDescription = "6 Business Days";
                            break;
                        case "Bound Printed Matter":
                            serviceDescription = String.Empty;
                            break;
                        case "Media Mail":
                            serviceDescription = "6 Business Days";
                            break;
                        case "Library Mail":
                            serviceDescription = String.Empty;
                            break;
                        default:
                            break;
                    }
                }

                if (shippingOptions.Find((s) => s.Name == serviceCode) == null)
                {
                    var shippingOption = new ShippingOption();
                    //TODO check whether we need to multiply rate by package quantity
                    shippingOption.Rate = Convert.ToDecimal(postalRate, new CultureInfo("en-US"));
                    shippingOption.Name = serviceCode;
                    if (!String.IsNullOrEmpty(serviceDescription))
                    {
                        serviceDescription = String.Format("({0})", serviceDescription);
                        shippingOption.Description = serviceDescription;
                    }
                    shippingOptions.Add(shippingOption);
                }
            }
        }
        while (!tr.EOF);
    }
    return shippingOptions;
}


---

You can make the service commitment (delivery time) strings bold via CSS; update the following style in styles.css to include the underlined property.

.checkout-data .shipping-options .shipping-option-item .option-description
{
    padding: 5px 0 5px 16px;
    font-weight:bold;
}

.
Hace 14 años
Thanks again for all the help in this project.
Hace 13 años
I too need to limit my shipping choices from the USPS, I do not want to offer all options. I am using 1.6, and can have someone do the changes for me so that I only display the shipping options I want, the comments have been very useful. However, it sure would be nice if one could simply chose or create a list of  available options from the USPS in the shipping configuration pages rather than doing it in the code. Just a thought for the future.
Hace 13 años
I totally agree with newgirl. We should not have to get into the code to configure shipping options or for that matter any other options. I understand this is open source software but not everyone that is looking at using inopCommerce has the ability to get into the code and modify it. Changing the look and feel of the software is one thing but basic functionality should be easier to use. At this point, this is one of the only things holding me back from moving my shopping web site to nopCommerce. I do have the a programming background but unfortunately it is 35+ years of legacy programming not asp.net. I can muck around in .net and follow examples, which is what I will probably end up doing to see if I can get the USPS shipping to work the way I want it to. Most of what is talked about in this thread is what I want to do. I am also looking at a cloud solution that let's me pick and choose which USPS, UPS, FedEx options I want to offer. The problem is, the cloud solution has a few things that don't offer the flexibility I need. Their solution is also a free solution. They have a forum just like this except you can vote on suggestions. They then take the most popular (and some of the others) and review them to see how easily they can be incorporated into the software.

Back to the shipping options. In my situation, my product is always a specific size. Based on this, I know how many pieces fit in each of the various size USPS flat rate priority mail boxes. I also know the total weight for each size box if I fill it. Using the cloud cart's setup, I can tell their shipping routine that for the small flat rate box, only offer it if it within the weight range I put in the rate method I created. I also have the ability to tell the shipping routine to not use the flat rate boxes in the USPS setup. Instead, use the shipping rate method that I created for the flat rate boxes. This works great. As the weight of the order increases, the software offers up the next size box and doesn't show the smaller size box. So the customer can then decide if they want to ship via the flat rate box or any of the other UPS and USPS shipping options that are displayed. It also automatically selects the lowest priced shipping option.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.