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;}
.