Auto-calculate Shipping

Contrib type: 
Module
Status: 
Initial upload
Compatibility: 
Ubercart 1.x

Uses JavaScript to click the Calculate Shipping button at checkout when the page loads. Mostly useful for shops that don't need to know the delivery address to calculate shipping.


PreviewAttachmentSize
autocalc_shipping.tar.gz437 bytes
Joined: 01/26/2008
Juice: 35

Thanks a ton!

Joined: 01/26/2008
Juice: 35

Is there any attachment coming here, or am I looking in the wrong place?

Joined: 08/07/2007
Juice: 6674

Heh, that would be kind of important, wouldn't it? Clean forgot when I made the post.

Joined: 07/16/2008
Juice: 5

It works fine for me except when i click "My billing information is the same as my delivery information.". If that box is clicked i have to click on "Review order" two times because on the first click i get "You must select a shipping option before continuing."

If i click somewhere on the page after the box "My billing information is the same as my delivery information." is checked it calculates the shipping again and the messege "You must select a shipping option before continuing." doesn´t show up. So I have to click somewhere else on the page after the box is checked to make it work.

How can i fix this?

Thanks in advance

Joined: 05/31/2008
Juice: 65

If I use firefox, and doesn't click "calculate shipping", the warning message "You must select a shipping option before continuing." will appear.

Once I cliced the button, I can continue. I logged in to test it in firefox. But I can't reproduce the problem if I use IE as anonymouse user.

Joined: 09/09/2008
Juice: 5

We have configured our Ubercart installation with two fixed-rate shipping options: Free Ground Shipping and $60 Overnight Shipping. They are presented to the customer in this order.

We have also deployed this autocalc_shipping contributed module (http://www.ubercart.org/contrib/3633), which does nothing more than push a 1-liner jquery script that clicks the "Calculate Shipping Cost" button on page render so the user does not have to.

If the user submits the form with invalid information - such as invalid CC# - the same form comes back with an error message at top (as expected), but the "Calculate Shipping Cost" radio buttons do not retain their previously-selected value.

In our case, for example, if a user selects "$60 Overnight Shipping" and enters an invalid CC#, the form comes back with Free Ground Shipping selected (instead of the "$60 Overnight Shipping") alongside the error messages.

Joined: 10/08/2007
Juice: 118

This is such a small, but great enhancement!

Joined: 11/17/2008
Juice: 7

This module doesn't work with the 6.x drupal due to API changes in hook_form_alter, and module .info file checking when installing the module. Two fixes:

to autocalc_shipping.info, append:
core = 6.x
php = 5.0

and to autocalc_shipping.module, change line 3 from:
function autocalc_shipping_form_alter($form_id,&$form){

to:
function autocalc_shipping_form_alter(&$form,$form_state,$form_id){

and you should be good to go.

Joined: 02/26/2009
Juice: 2

Hi,
I have tried to apply these changes - the module is still disable in the module list,
Any other suggestions?

BR
Itzhak

Joined: 03/07/2009
Juice: 2

Well, I have done this and it is sucesfully working with 6.10 now:

autocalc_shipping.info:

name = autocalc shipping
description = "Autocalculating shipping - 6.x."
version = "6.x-1.0"
core = "6.x"
project = "autocalc_shipping"
datestamp = "1218681903"

autocalc_shipping.module:

<?php
function autocalc_shipping_form_alter(&$form,$form_state,$form_id){
  if (
$form_id == 'uc_cart_checkout_form'){
   
drupal_add_js('$(document).ready(function(){
      $("input[@id*=quote-button]").click();
      $("input[@id*=quote-button]").hide();
    });'
, 'inline');
  }
}
?>
Joined: 04/10/2009
Juice: 36

Hi, I have done exactly what was suggested by conspirolog. However, it didn't work for me and I wondering why...

I am getting this message once I have installed the module,
"Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\drupal\includes\common.inc on line 501"

I am using Drupal 6 and Ubercart 2. Is it the script above not compatible with the versions that I am using?

Can the above method "auto re-calculate" the shipping charges whenever the customer changes his/her address? So that the customer do not need to hit the 'calculate shipping' button manually.

Thanks. Really need someone to advice.

Best Regards,
Dennis

Joined: 07/03/2009
Juice: 2

For latest Drupal 6 update the files to the following:

the .info file:

name = Auto-calculate Shipping
description = "Use JavaScript to automatically click the Calculate Shipping button at checkout."
version = "6.x-1.0"
core = "6.x"
package = "Ubercart - fulfillment"
datestamp = "1218681903"

the module file:

<?php
function autocalc_shipping_form_alter(&$form,$form_state,$form_id){
  if (
$form_id == 'uc_cart_checkout_form'){
   
drupal_add_js('$(document).ready(function(){
      $("input[id*=quote-button]").click().hide();
    });'
, 'inline');
  }
}
?>

FYI I removed the "@" symbol from the jquery selector. It was depreciated since version 1.2 and throws errors if you use 1.3. And the naming convensions for the latest drupal info files is different for it to work.

Joined: 07/17/2009
Juice: 6

Is there a way to modify this to also auto-calc shipping based on shipping profile?

I have two shipping profiles. One for domestic shipping and one for International shipping. It would be nice if the shipping options changed when the ship-to country is modified. As it is now, I need to populate the Billing address in order for the shipping profile to change. I have Workflow set up to base the shipping profile on ship-to country.

Thanks.

Joined: 04/13/2009
Juice: 33

Thank you for this! Works perfectly Smiling

Joined: 12/07/2009
Juice: 19

is there any way to get this module to actually remove the "Calculate Shipping Costs" section of the checkout page? I know that it can be disabled, but then shipping costs aren't calculated (I'm essentially using flatrate shipping). Here it calculates automatically, but leaves the "Calculate Shipping Costs" section there even though there is no need since there are no options for the customer to click.

Joined: 03/18/2009
Juice: 23

Hi, thanks for that module!
Are you planning to add copatibility with the 6.15 version of Drupal core?
One more thanks.

Joined: 09/01/2008
Juice: 23

@aluminium The code works fine with 6.15

I picked up a problem with this way of doing it.
When there is an empty required form field in the address, the page will reload with the error message. This causes the JS to trigger again which will reset the shipping quotes. The user now has to re-select a shipping method.
Is there a way that the JS will not trigger on form error?

Joined: 09/01/2008
Juice: 23

Fix the above by checking if messages error class exists.

<?php
function autocalc_shipping_form_alter(&$form,$form_state,$form_id){
  if (
$form_id == 'uc_cart_checkout_form'){
   
drupal_add_js('$(document).ready(function(){
    if($(".messages.error").length == 0) {
      $("input[id*=quote-button]").click().hide();
    }
    else {
        $("input[id*=quote-button]").hide();
    }
    });'
, 'inline');
  }
}
?>