Developer forum

Forum » Development » DW 9 ShippingProvider with notification subscriber

DW 9 ShippingProvider with notification subscriber

Ivan Marijanović
Ivan Marijanović
Reply

I am trying to achivw following:

1. Implementing ShippingProvider which will get all the delivery points to user

2. After the chechout done it will connect to service url and print the shipping documents / order shipping form provider

I tried implementing two classes one imheriting ShippingProvider with all parameters and another one inheriting NotificationSubscriber.

I cannot access paramters in ShippingProvider from NotificationSubscriber. I can access them but they are empty even thou I filed them in in backend.

This is NotificationSubscriber. DPD is ShippingProvider class.

[Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.CheckoutDoneOrderIsComplete)]

public class DPDOnCheckoutDone : Dynamicweb.Extensibility.Notifications.NotificationSubscriber
{
    #region Parameters
    private DPD dpd { get; set; }
    #endregion

    public DPDOnCheckoutDone()
    {
        dpd = new DPD();
    }

    public override void OnNotify(string notification, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
    {
        
        if (args == null)
            return;

        if (!(args is Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.CheckoutDoneOrderIsCompleteArgs))
            return;


        Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.CheckoutDoneOrderIsCompleteArgs checkoutDoneOrderIsCompleteArgs = args as Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.CheckoutDoneOrderIsCompleteArgs;


        if (checkoutDoneOrderIsCompleteArgs.Order.ShippingMethod == "DPD")
        {
            
        }
    }

}

Ivan


Replies

 
Ivan Marijanović
Ivan Marijanović
Reply

It looks like the ShippingProvider does not loads the parameters.

 

This is code:

public class DPD : ShippingProvider
{
    #region Parameters
    [AddInParameter("EasyShip service URL"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string serviceURL { get; set; }
    [AddInParameter("EasyShip service user name"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string username { get; set; }
    [AddInParameter("EasyShip service password"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string password { get; set; }
    [AddInParameter("Sender name"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string sender_name { get; set; }
    [AddInParameter("Sender city"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string sender_city { get; set; }
    [AddInParameter("Sender post code"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string sender_pcode { get; set; }
    [AddInParameter("Sender country"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string sender_country { get; set; }
    [AddInParameter("Sender street"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string sender_street { get; set; }
    [AddInParameter("Sender phone"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string sender_phone { get; set; }
    [AddInParameter("Sender email"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string sender_email { get; set; }        
    [AddInParameter("Shipping document outputh path/folder"), AddInParameterEditor(typeof(TextParameterEditor), "")]
    public string shippingDocumentOutputPath { get; set; }
    [AddInParameter("Use delivery address if specified"), AddInParameterEditor(typeof(YesNoParameterEditor), ""),
    AddInDescription("Use delivery address if specified otherwise use billing address")]
    public bool useDeliveryAddressIfPresent { get; set; }
    [AddInParameter("Test mode"), AddInParameterEditor(typeof(YesNoParameterEditor), "")]        
    public bool test { get; set; }

    #endregion

    public string testString { get; set; }
    /// <summary>
    /// Default constructor
    /// </summary>
    public DPD()
    {
        useDeliveryAddressIfPresent = true;
        testString = "test";            
        testString =this.password;
    }
}

 

Ivan

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Ivan

In your notification subscriber you do this:

  public DPDOnCheckoutDone()
    {
        dpd = new DPD();
    }

That will create an empty instance of your shipping provider with no settings loaded on the properties.

Instead you should create an instance of the shipping provider using information about the current shipping provider on the order:

var shipping = Services.Shippings.GetShipping(checkoutDoneOrderIsCompleteArgs.Order.ShippingMethodId);
var shippingProvider = ShippingProvider.GetShippingProviderByShipping(shipping);
if (shippingProvider is DPD)
{
    //This is a DPD shipping provider
}

 

Votes for this answer: 1
 
Ivan Marijanović
Ivan Marijanović
Reply

Thank you Nicolai!

Ivan

 

You must be logged in to post in the forum