Auto-calculate Shipping

Contrib type: 
Module
Status: 
Initial upload

Downloads

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
adamohern's picture
Offline
Joined: 01/26/2008
Juice: 35
much obliged!

Thanks a ton!

adamohern's picture
Offline
Joined: 01/26/2008
Juice: 35
attachment?

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

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6855
Re: attachment?

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

manjee's picture
Offline
Joined: 07/16/2008
Juice: 5
Strange problem

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

goldknight's picture
Offline
Joined: 05/31/2008
Juice: 65
Re: Strange problem

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.

bshensky's picture
Offline
Joined: 09/09/2008
Juice: 6
Does this module cause selected shipping to be lost on submit?

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.

scottrigby's picture
Offline
Getting busy with the Ubercode.
Joined: 10/08/2007
Juice: 122
Thanks Lyle :)

This is such a small, but great enhancement!

karlis's picture
Offline
Joined: 11/17/2008
Juice: 12
Drupal 6 Version

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.

imoreno's picture
Offline
Joined: 02/26/2009
Juice: 2
autocalc is not working with drupal 6

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

BR
Itzhak

conspirolog's picture
Offline
Joined: 03/07/2009
Juice: 2
Re: autocalc is not working with drupal 6

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');
  }
}
?>
DLZJ's picture
Offline
Joined: 04/10/2009
Juice: 48
Problem with "Fatal Error"....

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

gdub22's picture
Offline
Joined: 07/03/2009
Juice: 3
Use this

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.

nelslynn's picture
Offline
Joined: 07/17/2009
Juice: 6
Shipping profiles

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.

mkrapf's picture
Offline
Joined: 04/13/2009
Juice: 34
Thanks

Thank you for this! Works perfectly Smiling

rl9022's picture
Offline
Joined: 12/07/2009
Juice: 20
Re: Use this

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.

aluminium's picture
Offline
Joined: 03/18/2009
Juice: 35
Re: Auto-calculate Shipping

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

Max_Headroom's picture
Offline
Joined: 09/01/2008
Juice: 47
Re: Auto-calculate Shipping

@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?

Max_Headroom's picture
Offline
Joined: 09/01/2008
Juice: 47
Re: Re: Auto-calculate Shipping

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');
  }
}
?>
aluminium's picture
Offline
Joined: 03/18/2009
Juice: 35
Re: Re: Auto-calculate Shipping

Strangely, for me does not work in version 6.16 too Smiling

hiddentao's picture
Offline
Joined: 04/29/2010
Juice: 51
Re: Auto-calculate Shipping

Hey guys, I've modified the code so that it now does the following:

  • Hides the "Click to calculate shipping" button
  • Renames the fieldset to "Shipping costs"
  • Only simulates a button click on page load if a country is already selected
  • Ensures that the button gets clicked whenever the country is changed by the user

I renamed the module to uc_autocalc_shipping so that in my modules/ folder it shows up near the other ubercart modules.

I've tested it on Ubercart 6.x-2.2 on Drupal 6.16.

ZIP file attached.

AttachmentSize
uc_autocalc_shipping.zip 966 bytes
aluminium's picture
Offline
Joined: 03/18/2009
Juice: 35
Re: Re: Auto-calculate Shipping

I do not use the "Country" address field so the module does not work. Even if I add a that field module does not hide the button "Click to calculate shipping".

hiddentao's picture
Offline
Joined: 04/29/2010
Juice: 51
Re: Re: Re: Auto-calculate Shipping

Under normal circumstances (i.e. without this module), does it auto-recalculate the shipping when you change the delivery address?

I've attached an updated version of the module. Hopefully button hiding will work in this one.

AttachmentSize
uc_autocalc_shipping.zip 964 bytes
aluminium's picture
Offline
Joined: 03/18/2009
Juice: 35
Re: Re: Re: Re: Auto-calculate Shipping

Unfortunately I use flat rate and conditional action for calculate shipping cost, so delivery address do not has matter.

a_c_m@drupal.org's picture
Offline
Bug Finder
Joined: 01/02/2008
Juice: 288
Re: Auto-calculate Shipping

Great little module, could be further enhanced by also checking for changes to state and even postal code, but then you would also probably want to add some kind of admin interface (to select which trigger the update) and time out, so it only updates once.

I think, really, this should be part of the default functionality, i can't see why a user wants to click an extra button.

ribblevalley's picture
Offline
Joined: 10/06/2009
Juice: 80
Re: Auto-calculate Shipping

What a great little module.

I've slightly modified this for my use so it can now be used with the cart pane for calulating shipping, ideal for when customers are glancing at their cart page.

I'm using as follows in a seperate module...

uc_autocalc_shipping_pane.info

name = Autocalc Shipping on Cart Pane
description = "Use JavaScript to hide fields and automatically click the Calculate button on the cart pane."
version = "6.x-1.1"
core = "6.x"
package = "Ubercart - fulfillment"

uc_autocalc_shipping_pane.module

<?php

/**
* Implementation of hook_form_alter()
*/
function uc_autocalc_shipping_pane_form_alter(&$form,$form_state,$form_id){
  if ('uc_cart_pane_quotes' == $form_id){
  // hide the postal code and zone boxes
  $form['delivery_postal_code']['#type'] = 'hidden';
  $form['delivery_zone']['#type'] = 'hidden';
  // ensure those boxes are not required
  $form['delivery_postal_code']['#required'] = false;
  $form['delivery_zone']['#required'] = false;
  // javascript to make the click
  drupal_add_js('$(document).ready(function(){
    var shipping_button = $("input[id*=get-quote]");
    shipping_button.hide();   
    // click submit button when country is changed
    var selected_country = $("select[id*=delivery-country]");
    selected_country.change(function(){
    shipping_button.submit();
  });   
    // if country already selected then click the submit button
    if (undefined != selected_country.val())
    shipping_button.submit();
    });', 'inline');
  }
}

make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 511
Re: Auto-calculate Shipping

It works with Drupal 6.20

Hi,

Thanks "hiddentao #22 Submitted on Fri, 05/07/2010 - 21:02 ", this version works with latest Drupal and Ubercart.

But :Riddlevalley #25 Submitted on Tue, 09/21/2010 - 22:54 " I am sorry i cannot make it work on cart page:

I see a menu where you can select your country but the shipping price doesn't show even when i select another country that the default selected
And on the Checkout page I still need to click to calculate the shipping cost ?

Any help ?

Thanks a lot.

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Re: Re: Auto-calculate Shipping

Subscribing, interested in checkout page working also!
greetings, Martijn

make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 511
help ?

I wonder if we will get some help here ?

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Re: help ?

Yea...some help needed...is this great little module also language independent?
My friend tries to get to my first e-shop I am building. And with me the autocalc works perfectly, but on her side (different language), it keeps waiting very long..and then it says "transactioncosts could not be calculated"...
Anyone suggestions?

Somehow I was able to get the stuff working using uc_checkout_tweaks. I was able to disable the order preview, and then the module worked!
Does anyone have also a version with possibility to translate "shipping cost" in my language?

greetings,
Martijn

make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 511
uc checkout tweak

Thanks a lot, i didn't know uc checkout tweaks !

ratinakage's picture
Offline
Joined: 05/12/2010
Juice: 84
2.x?

Hi,

Does this module work with UberCart 2.x?

Thanks!

Scott M. Sanders's picture
Offline
Joined: 04/24/2009
Juice: 326
Re: Auto-calculate Shipping

Yes, see above.

ratinakage's picture
Offline
Joined: 05/12/2010
Juice: 84
Thanks!!

#22 works exactly as I wanted it...

Thanks... Eye-wink

ratinakage's picture
Offline
Joined: 05/12/2010
Juice: 84
One request

*edit - never mind

rectangle's picture
Offline
Joined: 08/08/2010
Juice: 37
Thanks for this.I am having

Thanks for this.
I am having trouble changing "Shipping quotes are generated automatically when you enter your address and may be updated manually with the button below." to "Shipping quotes are generated automatically when you enter your address." Can't seem to change it using the String Overrides module or manually editing uc_quote.module or uc_quote.admin.inc
Any ideas would be appreciated.

Never mind. I figured it out: admin/store/settings/quotes/edit

Yuri's picture
Offline
Joined: 05/26/2010
Juice: 35
Re: Auto-calculate Shipping

Doesn't work for latest UC6.x-2.4 D6.20, maybe someone can check if its just me, or that we need a patch.

mahitha's picture
Offline
Administrator
Joined: 11/03/2009
Juice: 538
Re: Re: Auto-calculate Shipping

Check for the javascript errors, shipping method is enabled, conditional actions return true etc.

gmopinillosv's picture
Offline
Joined: 05/25/2011
Juice: 27
Hello thereCould somebody

Hello there

Could somebody tell me if this work for Drupal 7.7 and Ubercart 7.X-3.0-beta4 ????

When I changed Buton text "Continue shopping" to link text, calculate shipping cost (calculate buton) worked for a instant.

But it not working any more.

I need help, pleeeeeeese.

gmopinillosv's picture
Offline
Joined: 05/25/2011
Juice: 27
Hello again

Hello there

Yeah , I think it is something about javascript but i do not know how check it .

Thanks in advance.

gmopinillosv's picture
Offline
Joined: 05/25/2011
Juice: 27
Hello Maitha Could you tell

Hello Maitha

Could you tell me how check javascript errors?

thanks

mahitha's picture
Offline
Administrator
Joined: 11/03/2009
Juice: 538
Re: Hello Maitha Could you tell

Try using Firefox browser Firebug or Chrome Developer tools to debug for the javascript errors.

Hobokoto's picture
Offline
Joined: 04/28/2010
Juice: 101
Re: Auto-calculate Shipping

I had a problem with this contrib, and translating the title.

It acts independently of the Drupal language system because it replaces the Shipping title with it's own, through Javascript.

I just commented out the part in the contrib that changes the title... now the regular Drupal shipping title is back, and translateable. GREAT!

uc_autocalc_shipping.module

$("#quotes-pane legend a").text("Shipping cost");

to

// $("#quotes-pane legend a").text("Shipping cost");

Hobokoto's picture
Offline
Joined: 04/28/2010
Juice: 101
Re: Auto-calculate Shipping

I got re-auto-calculation to work on state change by just duplicating some lines in the module, renaming country to zone.

Original:
// click button when country is changed
var selected_country = $("#edit-panes-delivery-delivery-country");
selected_country.change(function(){
shipping_button.click();
});

Copied and changed to:
// click button when state is changed
var selected_state = $("#edit-panes-delivery-delivery-zone");
selected_state.change(function(){
shipping_button.click();
});

jberg's picture
Offline
Joined: 03/26/2011
Juice: 33
Here was my problem, and the solution that worked for me

Using Drupal 6.26 and Ubercart 2.9, using a Flat Rate Shipping.

It was working fine when the user would get to the checkout page the first time. But after hitting the Review Order button, and a field was missing (returning the user to the checkout page with error message pointing out missing fields). It would NOT recalculate the total to include the shipping. I couldn't get it to recalculate the shipping unless I either added something else to the cart or removed the items I had and re-added them. Basically, it wouldn't add the shipping to the total unless the shipping amount changed when going back to the checkout page after the first load.

I was using #12's method and figured out it was hiding the button but not clicking it again (on reload of checkout page). So I went back to #10's code and only removed the @ symbol from the ".click" action, and left it on the ".hide" action (for some reason it didn't work at all when I removed the ".hide" line all together).

This is what I did.

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');
  }
}

Then just hid that button in my theme style sheet (.css)

input#edit-panes-quotes-quote-button {
display:none;
}

I'd be interested in a better way to do this. But it worked for me.