The following changes will enable residential rates for the FedEx shipping rate computation method and allow you to set an additional fee for the rates (both configurable in Administration -uncheck the checkbox for commercial rates and use 0 for no additional fee).
Edit file:
Shipping\Nop.Shipping.FedEx\FedExComputationMethod.cs and modify the
SetDestination(...) function with the new lines in bold (starts at line #114):
private void SetDestination(RateRequest request, ShipmentPackage ShipmentPackage)
{
request.RequestedShipment.Recipient = new Party();
request.RequestedShipment.Recipient.Address = new Address();
if (SettingManager.GetSettingValueBoolean("ShippingRateComputationMethod.FedEx.UseResidentialRates", false))
{
request.RequestedShipment.Recipient.Address.Residential = true;
request.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
} request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { "Recipient Address Line 1" };
request.RequestedShipment.Recipient.Address.City = ShipmentPackage.ShippingAddress.City;
if (ShipmentPackage.ShippingAddress.StateProvince != null)
{
request.RequestedShipment.Recipient.Address.StateOrProvinceCode = ShipmentPackage.ShippingAddress.StateProvince.Abbreviation;
}
else
{
request.RequestedShipment.Recipient.Address.StateOrProvinceCode = string.Empty;
}
request.RequestedShipment.Recipient.Address.PostalCode = ShipmentPackage.ShippingAddress.ZipPostalCode;
request.RequestedShipment.Recipient.Address.CountryCode = ShipmentPackage.ShippingAddress.Country.TwoLetterISOCode;
}
With this change, you will no longer have "FEDEX GROUND" displayed as a shipping method as it is only for commercial addresses; instead you will have "GROUND HOME DELIVERY" which is for residential.
---
In the same file, to have an optional additional fee added to each rate, modify the
ParseResponse(RateReply reply) function with the changes in bold (function starts at line #223):
private ShippingOptionCollection ParseResponse(RateReply reply)
{
decimal additionalFee = SettingManager.GetSettingValueDecimalNative("ShippingRateComputationMethod.FedEx.AdditionalFee", 0); ShippingOptionCollection result = new ShippingOptionCollection();
Debug.WriteLine("RateReply details:");
Debug.WriteLine("**********************************************************");
foreach (RateReplyDetail rateDetail in reply.RateReplyDetails)
{
Debug.WriteLine("ServiceType: " + rateDetail.ServiceType);
for (int i = 0; i < rateDetail.RatedShipmentDetails.Length; i++)
{
RatedShipmentDetail shipmentDetail = rateDetail.RatedShipmentDetails[ i ];
Debug.WriteLine("RateType : " + shipmentDetail.ShipmentRateDetail.RateType);
Debug.WriteLine("Total Billing Weight : " + shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Value);
Debug.WriteLine("Total Base Charge : " + shipmentDetail.ShipmentRateDetail.TotalBaseCharge.Amount);
Debug.WriteLine("Total Discount : " + shipmentDetail.ShipmentRateDetail.TotalFreightDiscounts.Amount);
Debug.WriteLine("Total Surcharges : " + shipmentDetail.ShipmentRateDetail.TotalSurcharges.Amount);
Debug.WriteLine("Net Charge : " + shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount);
Debug.WriteLine("*********");
//take first one
if (i == 0)
{
ShippingOption shippingOption = new ShippingOption();
string userFriendlyServiceType = GetUserFriendlyEnum(rateDetail.ServiceType.ToString());
shippingOption.Name = userFriendlyServiceType;
shippingOption.Rate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount
+ additionalFee;
result.Add(shippingOption);
}
}
Debug.WriteLine("**********************************************************");
}
return result;
}
---
To make residential rates and additional fees configurable in the FedEx configuration template in Administration, edit file:
Administration\Shipping\FedExConfigure\ConfigureShipping.ascxAdd the following at line #57
<tr>
<td class="adminTitle">
Use Residential Rates:
</td>
<td class="adminData">
<asp:CheckBox ID="cbUseResidentialRates" runat="server">
</asp:CheckBox>
</td>
</tr>
<tr>
<td class="adminTitle">
Additional Fee [<%=CurrencyManager.PrimaryStoreCurrency.CurrencyCode%>]:
</td>
<td class="adminData">
<nopCommerce:DecimalTextBox runat="server" ID="txtAdditionalFee" Value="0"
RequiredErrorMessage="Value is required" MinimumValue="0" MaximumValue="999999"
RangeErrorMessage="The value must be from 0 to 999999" CssClass="adminInput">
</nopCommerce:DecimalTextBox>
</td>
</tr>
---
Edit file:
Administration\Shipping\FedExConfigure\ConfigureShipping.ascx.csAdd the following to the
BindData() function:
txtAdditionalFee.Value = SettingManager.GetSettingValueDecimalNative("ShippingRateComputationMethod.FedEx.AdditionalFee");
cbUseResidentialRates.Checked = SettingManager.GetSettingValueBoolean("ShippingRateComputationMethod.FedEx.UseResidentialRates");
Add the following to the
Save() function:
SettingManager.SetParam("ShippingRateComputationMethod.FedEx.AdditionalFee", txtAdditionalFee.Value.ToString());
SettingManager.SetParam("ShippingRateComputationMethod.FedEx.UseResidentialRates", cbUseResidentialRates.Checked.ToString());
This is for version 1.40 and you will need to recompile the solution.
.
*Post updated to include configuration options*