Hi, I'm setting up Oscar, and I'm implementing a custom shipping method.
My shipping method uses a REST API to contact a server that calculates actual UPS shipping charges when given the contents of the shipment.
I forked the shipping app, implemented the Repository and Method, and implemented the calculate method of my Method class.. that all works!
Here's the problem:
When I put some items in the cart, and then view cart. Oscar calls Repository.get_available_shipping_methods(), however, the shipping_addr argument to that method is None, which makes sense, because the customer has not be asked for a shipping address yet.
So I return a tuple containing an instance of my shipping method.
Oscar then calls MyMethod.calculate(basket) on that instance, but I can't calculate anything, because there's no address yet. I am expected to return a Price, but I can't...
So, I tried returning None.. that causes an exception.
Then I tried, in
get_available_shipping_method, returning an empty tuple if no shipping_addr is supplied. That's not ok either, Oscar tells me to implement some shipping methods...
So.. just for testing, I tried having calculate() return a zero price if there's no address supplied. Sure enough, my cart displays, showing my shipping method with a zero price.
Then I can go on to the next page where it asks the customer to select an address. I select one, and sure enough,
get_available_shipping_methodsis called again, this time with the shipping_addr, and I can successfully calculate the shipping rate.
(Then, the payment page is displayed.. which for me is not implemented yet, because we use
authorize.net.. I'll have to write that).
Can anyone tell me, what's the correct way to do this? I want to delay the shipping calculation until after the customer has selected or entered the address. I don't want to calculate or display a shipping price in the cart at all.
Thanks
Ben