Index: uc_ratequote.module =================================================================== --- uc_ratequote.module (revision 448) +++ uc_ratequote.module (revision 584) @@ -76,7 +50,11 @@ 'type' => 'order', 'callback' => 'uc_ratequote_quote', 'accessorials' => array( - t('Shipping Rate'), + t('Standard Shipping/Handling/Insurance Rate'), + t('RUSH: 3-5 days (order BEFORE 3pm EST); +$15 to Standard S/H'), + t('OVERNIGHT: Next business day delivery (order BEFORE 3pm EST); +$30 to Standard S/H'), + t('CANADA: +$12 to Standard S/H (3-5 weeks)'), + t('INTERNATIONAL: Air; +$40 to Standard S/H') ), ), 'weight' => $weight['ratequote'], @@ -237,43 +213,51 @@ * A JSON object containing the shipping quote for the order. */ function uc_ratequote_quote($products, $details){ + $rate = 0; foreach ($products as $product){ $node = node_load($product->nid); $total += $node->sell_price * $product->qty; + # this total should have any discounts applied to it, before we calculate the shipping rate.. } + + $discounts = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id=%d AND type='discount'", $arg1->order_id); + if (empty($discounts)) { + return; + } + $discount_total = 0; + + while ($data = db_fetch_object($discounts)) { + // store as negative + $total -= $data->amount; + } + $country = uc_get_country_data(array('country_id' => $details['country'])); + $result = db_query("SELECT * FROM {uc_ratequotes}"); while ($r = db_fetch_object($result)) { if($total <= $r->max && $total >= $r->min) { $rate = $r->rate; $percent = $r->percent; -# debug -# ob_start(); print_r($r); -# drupal_set_message(ob_get_contents()); -# ob_end_clean(); } } + # calculate percentage, if note $rate is given + if ($rate <= 0 && $percent > 0) { + $rate = $total * ($percent / 100); + } + $method = uc_ratequote_shipping_method(); - if ($rate > 0) { + if ($country[0]['country_iso_code_2'] == 'US') { $quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $method['ratequote']['quote']['accessorials'][0]); + $quotes[] = array('rate' => $rate+15, 'format' => uc_currency_format($rate+15), 'option_label' => $method['ratequote']['quote']['accessorials'][1]); + $quotes[] = array('rate' => $rate+30, 'format' => uc_currency_format($rate+30), 'option_label' => $method['ratequote']['quote']['accessorials'][2]); + } elseif ($country[0]['country_iso_code_2'] == 'CA') { + $quotes[] = array('rate' => $rate+12, 'format' => uc_currency_format($rate+12), 'option_label' => $method['ratequote']['quote']['accessorials'][3]); } else { - $rate = $total * ($percent / 100); - $quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $method['ratequote']['quote']['accessorials'][0]); + $quotes[] = array('rate' => $rate+40, 'format' => uc_currency_format($rate+40), 'option_label' => $method['ratequote']['quote']['accessorials'][4]); } return $quotes; } - -# unused? mebbe not.. -function uc_ratequote_quote_order($products, $details){ - $method = uc_ratequote_shipping_method(); - $rate = variable_get('uc_ratequote_order_rate', 0); - $percent = variable_get('uc_ratequote_order_percent', 0); - - $quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $method['order_rate']['quote']['accessorials'][0]); - - $quotes; -}