How do I automate shipping calculation? Is it possible to auto calculate shipping for Drupal 7? Is there a way to automate with coupons integrated as well? e.g. Free Shipping coupon.

Currently, if someone were to input a free shipping coupon, these are the necessary steps.


Enter FREESHIPPING code
Apply to order
Update order
Calculate shipping
Select "Free Shipping" instead of "Paid Shipping"


I would like to exclude the last three steps as it's a pretty long process, and some customers might not know to click on Calculate Shipping after clicking Update order. They may think the coupon is broken. Anyway, applying a free shipping code is self explanatory. What I'm looking for is a way to automate the calculate shipping when users enter or change the delivery country  when Apply to Order is clicked on the coupon pane.

Do you have any thought?
I'm still using D6 but I did something similar with jQuery:

Make a mymodule.module file that goes like this:

&lt;?php

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id){
  if ($form_id == 'uc_cart_checkout_form'){

    drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');

  }
}


The format of your hook_form_alter may be different in 7, but there are tutorials all over the place for this. The point is that you use drupal_add_js (again, format may differ) to cram some javascript onto only the form with the ID you want - your checkout form.

Make a mymodule.info that goes like this:


name = Re-calculate Shipping
description = Use JavaScript to automatically click the Calculate Shipping button at checkout.
core = 6.x
dependencies[] = uc_quote
package = "Example.com custom modules"


(But you're core is 7.x - copy another module's info file.)
And make a mymodule.js file that goes something like this:

$(document).ready(function(){
      $("#edit-panes-quotes-quote-button").click();
      $("#edit-panes-delivery-copy-address").click();
});

$(document).ready(function(){
   $("#edit-panes-billing-billing-zone").change(function() {
      $("#edit-panes-quotes-quote-button").click();
   });
});

$(document).ready(function(){
   $("#edit-panes-delivery-delivery-zone").change(function() {
      $("#edit-panes-quotes-quote-button").click();
   });
});


Note that this just clicks the "calculate" button for the user, but I'm sure that you can work out how to use jQuery to click more things.

Imagine you have a drop-down select with the attribute id="cram".
In your js file you would use $("#cram") to select anything with the ID "cram":

$("#cram").change(function() {


Sticking .change() on the end triggers anything between the brackets after .change when the #cram element changes, such as when a different fruit / rodent is selected. we're triggering a function here, and it is defined in-situ.

Sticking .click() on the end of a selector clicks the selected element.

Enjoy :)