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,
- 0 lbs = Free
- 0 < order weight < 2 lbs = $2.00
- etc
Attachment Size uc_weightquote.module.gz 1.66 KB







Joined: 08/29/2007