1 reply [Last post]
mackay's picture
Offline
Internationalizationizer
Joined: 09/18/2007
Juice: 33
Was this information Helpful?

Hi guys,
I'm making a shipping module to suit my ever growing demands and I stuck for three days now on one thing, maybe anyone could give some advices.
The module is 7e flatrate mod. It has interface to add custom shipping rules to db, after that the enabled one for specific countries (thanks to shipping quotes) would be presented to customer but....
After pulling out those methods from db:
-------------
function uc_postman_shipping_method(){
$methods = array();
$enabled = variable_get('uc_quote_enabled', 0);

$result = db_query("SELECT * FROM {uc_postman} ORDER BY id");
while ($met = db_fetch_object($result)){

$methods['m'.$met->id] = array(
'id' => 'm'.$met->id,
'module' => 'uc_postman',
'title' => $met->name,
'enabled' => $enabled['m'.$met->id],
'quote' => array(
'type' => 'order',
'callback' => 'uc_postman_quote_order',
'accessorials' => array(
$met->name,
),
),
'weight' => $weight['m'.$met->id],
);}

return $methods;
}

------------------
I think I have to provide numerous callback functions (?) like:
-------------------
function uc_postman_quote_order($products, $details){

$result = db_query("SELECT * FROM {uc_postman} WHERE id = %d", 22);
$met = db_fetch_object($result);

$method = uc_postman_shipping_method();
$rate = $met->rate;

$quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $method['s'.$met->id]['quote']['accessorials'][0]);

return $quotes;
}------------------
And the thing is, I don't know how on earth I can put that callback functions in some kind of loop (?) or other clever method so as module would base on pure code, without any static variables - like that '22' standing for id.
I would be very grateful for any help, if it's possible. I spent so mouch time on that that even drupal song doesn't help me anymore Eye-wink

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Shipping module based on flatrate

I had been thinking about doing something very similar to this. I hadn't gotten very far, or I would have run into the same problem you have.

Fortunately, I have developer's prerogative, so I can just make a way for this to work. In the Bazaar version, there's a function called uc_quote_action_get_quote. On line 318 is where the shipping method callback is called, and we can just add the $method parameter to the end of the call. Like so:

<?php
    $quote_data
= call_user_func($method['quote']['callback'], $order->products, $details, $method);
?>

Then your function can use $method['id'] instead of 22.