Developer forum

Forum » Development » Change custom shipping method fee programmatically?

Change custom shipping method fee programmatically?

Dmitrij Jazel
Reply

Hi guys,

I am trying to create a custom shipping method.

I took a look at current sourcecode examples and as an example I take 

    [AddInName("SpecialDelivery"), AddInDescription("description...")]
    public class SpecialDelivery: ShippingProvider, IShippingDocumentProvider, IDropDownOptions

When you are setting this shipping method in the Administration, you can set a default Fee for this specific shipping method.

 

In the the parameters I add 

[AddInParameter("Special ocasion Price"), AddInParameterEditor(typeof(TextParameterEditor), "size=80")]
        public string SpecialOcasionPrice { get; set; }

So my question is what I want to overwrite that "default fee" with a "special ocasion price" if the order falls under certain conditions - than this must be applyed.

How do I set this special price to this shipping method programmatically?

 

Regards,

Dmitrij


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Then you need to implement an eCommerce.Orders.FeeProvider

It will give you an order instance, on that you have the delivery method.

http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.eCommerce.Orders.FeeProvider.html

BR Nicolai

Votes for this answer: 1
 
Dmitrij Jazel
Reply

Hi Nicolai,

Really good example! :) Thanks for sharing that, I saw that Fee provider some time ago.

But what if I have 2-3 different shipping methods, how do I control (or know) that this (currently selected in frontend) shipping method will invoke that Fee provider I just created?

In other words, how do I link your Fee provider example with my custom  Delivery method option?

All I can see now that it get's order instance, does SQL lookup, and than applyes 0.00 fee if needed. That's ok. but what if there are several shipping methods?

 

Regards,

Dmitrij

 
Dmitrij Jazel
Reply

Ok, just did some experimenting, As I understand now every time you hit the cart (in the frontend), Every Shipping method I have in the system will invoke the Fee provider code? 

This means that I can lookup Order.ShippingMethodID (inside fee provider FindFee()) and determine do I apply custom logics or not.

Correct?

 

Regards,

Dmitrij

 
Nicolai Høeg Pedersen
Reply

Yes, that is correct. And on the order, you have the delivery method as a property.

 
Dmitrij Jazel
Reply

Hi Nicolai,

Here I have my Fee provider

public class SpecialDeliveryProvider : Dynamicweb.eCommerce.Orders.FeeProvider
{
    public override Dynamicweb.eCommerce.Prices.PriceRaw FindFee(Dynamicweb.eCommerce.Orders.Order Order)
    {
        if (Order.ShippingMethodID == "SHIP4")
        {
            ReturnFee = new Dynamicweb.eCommerce.Prices.PriceRaw(123.45, Dynamicweb.eCommerce.Common.Application.DefaultCurrency);
        }
        return ReturnFee;
    }
}

It is based on your free shipping provider, to one you sent me a link previously.

 

Question is:

if I am trying to read that fee after order is complete, I am reading it like this right now:

var shippingPriceWithVAT = Order.ShippingFee.PriceWithVAT;

But I am getting 0 :/ is that correct way to read it? Or maybe I am missing something.

 

And if I trying to set Order.ShippingFee.PriceWithVAT in the Fee provider - I am getting null pointer.

Some suggestions on this one?

 

/Dmitrij

 

 

You must be logged in to post in the forum