jigoshop/jigoshop — pull request #413 by mindbuster (2011-11-15 15:31:03+00:00)
Title: Work In Progress - Don't merge yet. Shipping extension (requires feedback)

I have worked on putting the functionality into jigoshop to allow shipping to call shipping API's to return rates based on what is currently in the cart.

Please comment on whether or not this will fit in with the jigoshop core for the future. Feedback welcomed! I'd really like to see this or something like this implemented in the next release.

Current problem: Unfortunately in my stream, I'm unable to add new files. I have an abstract class that I'd like to add to the shipping folder. This is the necessary class to extend shipping_method so that we can have calculable shipping methods. eg. the user can create a class to call a specific shipping services API by extending this abstract class.

Things I kept in mind for this design:
1) Allow the ability for users to create their own 'calculable shipping methods' by extending the abstract class that I need to add to the shipping folder.
2) jigowatt could create a couple of these shipping methods to sell as extensions. (I have a prototype only for USPS shipping)
3) I wanted this extension to be as seamless as possible, so that if a user of the source code wanted to add their own shipping method, it's supposed to be as easy as it is to add current shipping methods.

I can include the prototype USPS shipping (that I created) as well if I can add more files to the source base.

There are still problems in the code that have to be ironed out, but i'm hoping that I have most of the functionality added already.

How the code works
1) the shipping method must have the jigoshop_calculator enabled for this to work
2) extend new abstract class jigoshop_calculable_shipping (this can be named something else if the name doesn't work. It extends shipping_method)
3) if the cart has in its available methods a jigoshop_calculable_shipping method, then code will execute the calculable method that gets created (only when enabled)
4) if an error returns from the service call to the API, the function returns an invalid value to disable showing anything to the customer, and the normal method of finding the lowest rate applies.
5) when a required value is filled out on the shipping calculator (whether its postalcode/zip or state/county) and submitted, this is when the calculable code can execute and then show options back to the user. Currently this shows up under the update totals button on the calculator. (also needs more thought for presentation on this part. Could use some help here)
6) If a customer selects a different value then the lowest price value, then jquery will execute an ajax command and update the shipping totals on the total cost of the cart. As long as a customer doesn't refresh their browser, this will work. If refresh happens, we'll automatically recalculate the lowest price.

some thoughts for updates. Change the service array so that we can put proper labels on the UI, and possibly add more information on the service array so that it is used for communication with the shipping service API's.

I really hope this is a help for your longer term goals.