Free Shipping thru Weight Quote

Posts: 4
Joined: 08/29/2007

I was struggling with various ways to allow some products to have zero shippings costs. After quickly looking around, I decided the best solution for my situation was to modify the uc_weightquote module.

Scenario: We sell various products, including CDs and tickets. Tickets are either mailed for free or picked up at the box office, while CDs are shipped USPS at $2.13 first pound + $0.34/lb additional. Assume CDs weigh 1/2 lb.

Problem: When buying only tickets, the 'base_rate' ($2.13) was still added.

Solution: Tickets weigh 0 lbs and CDs weigh 0.5 lbs. Modified uc_weightquote_quote() so that 'base_rate' is only added to orders over 0 lbs.

Modifications to uc_weightquote.module (or download file):

Replace

<?php
function uc_weightquote_quote($products, $details){
 
$rate = 0;
  foreach (
$products as $product){
   
$node = node_load($product->nid);
   
$rate += $node->weightquote * $product->qty * $product->weight;
  }
 
$rate += variable_get('uc_weightquote_base_rate', 0);
 
 
$method = uc_weightquote_shipping_method();
 
 
$quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $method['weightquote']['quote']['accessorials'][0]);
 
  return
drupal_to_js($quotes);
}
?>

With

<?php

function uc_weightquote_quote($products, $details){
 
$rate = 0;
 
$total_weight = 0;
  foreach (
$products as $product){
   
$node = node_load($product->nid);
   
$rate += $node->weightquote * $product->qty * $product->weight;
   
$total_weight += $product->weight;
  }

  if (
$total_weight > 0) {
   
$rate += variable_get('uc_weightquote_base_rate', 0);
  }
 
 
$method = uc_weightquote_shipping_method();
 
 
$quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $method['weightquote']['quote']['accessorials'][0]);
 
  return
drupal_to_js($quotes);
}
?>

Future: I will later try to modify it for shipping quotes based on weight ranges, e.g,

Posts: 4256
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Ahh, great idea. This should help some other folks who were looking for free shipping options in the past. Smiling

Posts: 21
Joined: 11/21/2007
Bug Finder

Future: I will later try to modify it for shipping quotes based on weight ranges, e.g,

* 0 lbs = Free
* 0 < order weight < 2 lbs = $2.00
* etc

Have you made any progress on this? It would help me a lot if you have.

--

Changing life as we know it, through the love, loyalty, and friendship of Jesus Christ.

Posts: 28
Joined: 01/14/2008

Everything helps a bit. Thanks for the article.

I modified your code to calculate LTL Freight Rates for IronPickets.com.

< 250 lbs  = X
< 500 lbs = y
< 2500 lbs = z

It would be nice to define the stair steps in the module itself and use the workflow NG to apply them.

Thanks,
David

--

David Strickland
Delante Solutions

Posts: 48
Joined: 10/08/2007
Getting busy with the Ubercode.

Hi,
I also wanted free shipping on a product (seems this shouldn't be impossible?)

I tried porelrio's code above... it seems to do something...

I made one of my products set to '0' weight.

During checkout, when a user clicks "click to calculate shipping" they get the following message:

undefined: Please enter the package weight.
There were problems getting a shipping quote. Please verify the delivery and product information and try again.
If this does not resolve the issue, please call in to complete your order.

Then, under Payment Method (Order total preview) I still see the first shipping option selected "U.S.P.S. First-Class Mail: $2.96". I wonder if this shipping option is selected because there was a "problem getting a shipping quote"?

Is there a way to add a friendly message, instead of this one, and to have the shipping quote show something like "$0" or "Free Shipping"?

I wonder if we could modify the if statement above, to add an 'else' – something like this?:

  if ($total_weight > 0) {
    $rate += variable_get('uc_weightquote_base_rate', 0);
  }
  else {
    // 1. Show a friendly message
    SORRY I'M NOT SURE HOW TO WRITE THE CODE FOR THIS, AND...
    // 2. Set default payment method to "Free Shipping $0.00"
    ALSO NOT SURE WHAT TO WRITE HERE, BUT YOU GET THE IDEA
  }

Though I'm not familiar enough with ubercart to suggest what to write here. Does anyone have an idea how to do this? Seems this would be pretty important if giving users free shipping on a product?

Thanks!
Scott