Custom Shipping Provider GetPrice Delivery trouble

Delford Chaffin asked on February 4, 2016 22:06

I'm trying to follow this example to create a custom shipping provider:

In my GetPrice method, every time I try to get the delivery address values, they are blank. For example:

System.Text.StringBuilder msg = new System.Text.StringBuilder();
msg.AppendFormat("AddressLine1: {0}", delivery.DeliveryAddress.AddressLine1);
msg.AppendFormat("<br />AddressLine2: {0}", delivery.DeliveryAddress.AddressLine2);
msg.AppendFormat("<br />AddressCity: {0}", delivery.DeliveryAddress.AddressCity);
msg.AppendFormat("<br />AddressState: {0}", delivery.DeliveryAddress.GetStateCode());
msg.AppendFormat("<br />AddressCountry: {0}", delivery.DeliveryAddress.GetCountryTwoLetterCode());
msg.AppendFormat("<br />AddressZip: {0}", delivery.DeliveryAddress.AddressZip);
EventLogProvider.LogInformation("FedExCarrierProvider", "GetPrice", msg.ToString());

... this shows the following in the EventLog:

AddressState: WV
AddressCountry: US

I cannot make the other fields load. I've tried delivery.DeliveryAddress.SetAddress() to no avail (I'm not really sure what that does).


Correct Answer

Delford Chaffin answered on February 9, 2016 16:43

For anyone else that runs into this issue, I ended up moving the addresses to a separate, earlier page and now the CustomCarrierProvider's GetPrice() method now has the address information. In other words, I didn't really "solve" the problem, I just worked around it. But it does seem like some kind of bug at this point to me.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Joshua Adams answered on February 4, 2016 22:14

Most likely there is an AddressID which will be populated. Just create your AddressInfo object based on that ID and use that instead.

AddressInfo addr = AddressInfoProvider.GetAddressInfo(delivery.addressid);

Not sure what object exactly delivery is, but there should be an addressid, either on that object or on the delivery.DeliveryAddress object.

0 votesVote for this answer Mark as a Correct answer

Delford Chaffin answered on February 4, 2016 22:33


AddressInfo addr = AddressInfoProvider.GetAddressInfo(delivery.DeliveryAddress.AddressID);

... and trying to write out that gives me the infamous: "Message: Object reference not set to an instance of an object."

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on February 4, 2016 22:48

Is there any place in your delivery object that you can get the addressID, What class is delivery using or based on?

0 votesVote for this answer Mark as a Correct answer

Delford Chaffin answered on February 4, 2016 23:15

See the link in the original question. The Delivery class is CMS.Ecommerce.Delivery and is in the signature of the GetPrice method in the ICarrierProvider interface.

namespace CMS.Ecommerce
    // Summary:
    //     Class representing a delivery (bunch of items shipped together using a shipping
    //     option).
    public sealed class Delivery
        public Delivery();

        // Summary:
        //     Custom data.
        public IDataContainer CustomData { get; internal set; }
        // Summary:
        //     Address where delivery is shipped to.
        public IAddress DeliveryAddress { get; internal set; }
        // Summary:
        //     Items shipped in this delivery. Only products and accessory product options
        //     are present.
        public IEnumerable<DeliveryItem> Items { get; internal set; }
        // Summary:
        //     The date of shipping (package departure from store).
        public DateTime ShippingDate { get; internal set; }
        // Summary:
        //     Shipping option used to deliver this delivery.
        public ShippingOptionInfo ShippingOption { get; internal set; }
        // Summary:
        //     Weight of whole package.
        public decimal Weight { get; internal set; }

In my GetPrice method, I can get the delivery Weight and Items and from the DeliveryAddress, I can call GetStateCode() and GetCountryTwoLetterCode(). The other properties of DeliveryAddress I cannot get to populate from the form on the page.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.