Many of us struggle with International Shipping and the AWESOME uc_marketplace module. Recently, we've had a calling for International deliveries. So, after a lot of work, I "HACKED" the following function - so that uc_marketplace works for international shipping, using USPS.
Now, I'm going to be candid, I REALIZE that HACKING is NOT GOOD. I also realize that someone could probably show me how to make this a patch. I would sure enjoy that, for the rest of you, who just want to see how I did it, here is the replacement function. I've inserted comments for your assistance.
Hope this helps someone!
function mp_quote_quote($products, $details) {
// These are the countries that are considered USA - so International Shipping is NOT a requirement. I got
// this information from uc_usps.module
$countries = array(16, 316, 630, 840, 850);
unset($_SESSION['mp_quote_rate']);
// pbv = products by vendor
// sort products into an array by vendor, so operations can be performed on a per vendor basis
$pbv = array();
foreach ($products as $product) {
$quote_method = db_result(db_query("SELECT quote_method FROM {mp_quote_products} WHERE nid = %d", $product->nid));
$pbv[$product->uid][$quote_method][] = $product;
}
$sqr = 0;
// sqr = shipping quote rate
// vp = vendor's products
// loop through vendors and perform operations (i.e. shipping calculations)
foreach ($pbv as $uid=>$vp) {
$quotes = array();
// retrieve a shipping quote for this vendor's products based on methods selected
// ===FLAT RATE QUOTE METHOD===
if (isset($pbv[$uid][0])) {
$flatrate_name = 'flatrate_'. variable_get('mp_quote_flatrate_id', 1);
$quote = uc_flatrate_quote($pbv[$uid][0], $details, array('id' => $flatrate_name));
if(empty($quote)) { // return if error retrieving quote
return $quote;
}
$sqr += $quote[0]['rate'];
$_SESSION['mp_quote_rate'][$uid] += $quote[0]['rate'];
}
// ===USPS QUOTE METHOD===
if (isset($pbv[$uid][1])) {
// Simple IF statement to check if the order will be delivered to USA
if (in_array($details['country'], $countries) ) { // USA Shipping
$quote = uc_usps_quote($pbv[$uid][1], $details, array('id' => 'usps'));
// Needed to use a NEW accumulator variable since the standard $quote[1]['rate'] is for USA and $quote[2]['rate'] will be used
// for international Shipping
$item_quote = $quote[1]['rate'];
} else { // International Shipping
// Literally we call the same function as for USA, but you will notice that I added a more DETAILED array
// for the METHOD. I got this right from uc_usps.module
$quote = uc_usps_quote($pbv[$uid][1], $details,
array( 'id' => 'usps_intl',
'module' => 'uc_usps',
'title' => t('U.S. Postal Service (Intl., Parcel)'),
'quote' => array(
'type' => 'small_package',
'callback' => 'uc_usps_quote',
'accessorials' => _uc_usps_intl_services(),),
'enabled' => 1,
'weight' => 0,));
// Here we accumulate the International Shipping Charges
$item_quote = $quote[2]['rate']; // International Shipping
}
if(empty($quote)) { // return if error retrieving quote
return $quote;
}
$markup_rate = db_result(db_query("SELECT markup_rate FROM {mp_quote_sellers} WHERE uid = %d", $uid));
// Last change, converted to $item_quote here.
$sqr += $item_quote + $markup_rate; // 1 = USPS Priority Mail Service Code (Ubercart)
$_SESSION['mp_quote_rate'][$uid] += $item_quote + $markup_rate;
}
}
$quotes['Shipping'] = array('rate' => $sqr, 'format' => uc_currency_format($sqr), 'option_label' => t('Shipping'));
return $quotes;
}