I am trying to narrow down the USPS shipping methods. I have read on here that I can do this by adding code into Solution\Shipping\Nop.Shipping.USPS\USPSComputationMethod.cs. I am using a switch method to do this and I will add my code below. I have gotten everything from 'System.Web.HttpUnhandledException' errors to it working only not showing all of the methods and only prices.
Another thing I tried was in Solution\Shipping\Nop.Shipping.USPS\USPSStrings.cs I commented All, and uncommented what I wanted...eg priority and parcel. But that errored with a box type error.
Please help
here is my code, if I take out my commented out area it wont work
private ShippingOptionCollection ParseResponse(string response, ref string error)
{
ShippingOptionCollection shippingOptions = new ShippingOptionCollection();
using (StringReader sr = new StringReader(response))
using (XmlTextReader tr = new XmlTextReader(sr))
do
// while (tr.Read())
{
// Read the next XML record
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;
}
// Process the inner postage XML
if ((tr.Name == "Postage") && (tr.NodeType == XmlNodeType.Element))
{
string serviceCode = "";
string postalRate = "";
string test1 = "";
bool i = false;
// while (tr.Read())
do
{
i = false;
tr.Read();
if ((tr.Name == "MailService") && (tr.NodeType == XmlNodeType.Element))
{
test1 = tr.ReadString();
//switch (test1) {
// case "Express Mail Hold For Pickup":
// i = true;
// break;
// case "Express Mail Flat Rate Envelope Hold For Pickup":
// i = true;
// break;
// case "Express Mail":
// i = true;
// break;
// case "Express Mail Flat Rate Envelope":
// i = true;
// break;
// case "Priority Mail":
// i = true;
// break;
// case "Priority Mail Flat Rate Envelope":
// i = false;
// break;
// case "Priority Mail Small Flat Rate Box":
// i = false;
// break;
// case "Priority Mail Medium Flat Rate Box":
// i = false;
// break;
// case "Priority Mail Large Flat Rate Box":
// i = false;
// break;
// case "Parcel Post":
// i = false;
// break;
// case "Bound Printed Matter":
// i = true;
// break;
// case "Media Mail":
// i = true;
// break;
// case "Library Mail":
// i = true;
// break;
// default :
// i = false;
// break;
//}
if (i == false)
{
serviceCode = test1;
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))
{
if (i == false)
{
postalRate = tr.ReadString();
tr.ReadEndElement();
if ((tr.Name == "Rate") && (tr.NodeType == XmlNodeType.EndElement))
break;
}
}
} while (!((tr.Name == "Postage") && (tr.NodeType == XmlNodeType.EndElement)));
if (shippingOptions.Find((s) => s.Name == serviceCode) == null)
{
ShippingOption 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;
shippingOptions.Add(shippingOption);
}
}
} while (!tr.EOF);
return shippingOptions;
}