How to reference checkout pane data for shipping quote calculation

Posts: 6
Joined: 09/18/2008

Somebody help or give me a lead. Anybody willing to help out for a fee?

Thank you in advance for any help.

I am developing a shipping quote method that is weight-based. The calculation of the shipping quote works like this: 1. Customer completes the delivery address details on the delivery pane at checkout. 2. Customer selects for delivery type either “Standard” or “Expess” in a new pane that I have included at checkout. 3. The shipping quote calculation will need zone and delivery type to return a shipping quote. The rates are stored in a table by zones. If the customer selected “Standard” as delivery type then the quote returned is (shipping rate * order weight) else quote is ((shipping rate * order weight) + Basic charge). Basic charge exists in the rate table.

My problem is how do I reference the delivery type information selected by the customer on the checkout form (deliverytype pane) so that I can use it in calculating the shipping quote.

The code for the new pane is:

<?php
function uc_deliverytype_checkout_pane() {
 
$panes[] = array(
   
'id' => 'deliverytype',
   
'callback' => 'uc_checkout_pane_deliverytype',
   
'title' => t('Delivery type method'),
   
'desc' => t('Customer selects how they want their order delivery.'),
   
'weight' => 5,
  );
  return
$panes;
?>

The callback function is:

<?php
function uc_checkout_pane_deliverytype($op, &$arg1, $arg2) {
  switch (
$op) {
    case
'view':
     
$description = t('Please select how you would want your order delivered to you.');

     
$options = preg_split('/[\r\n]+/', variable_get('uc_deliverytype_options', ''));
      for (
$i = 0; $i < count($options); $i++) {
        if (empty(
$options[$i])) {
          unset(
$options[$i]);
        }
      }
     
$options = array_merge(array(t('Standard')), $options,
                             array(
t('Express')));
     
$contents['deliverytype_source'] = array(
       
'#type' => 'select',
       
'#title' => t('Select a delivery type method'),
       
'#options' => drupal_map_assoc($options),
       
'#default_value' => $arg1->deliverytype['source'],
      );
      return array(
'description' => $description, 'contents' => $contents);

    case
'process':
      {
       
$arg1->deliverytype['source'] = $arg2['deliverytype_source'];
      }
      return
TRUE;
     
    case
'review':

      {
       
$review[] = array('title' => t('Delivery type selected'), 'data' => $arg1->deliverytype['source']);
      }
      return
$review;
  }
}
?>

Here is the hook_quote. Notice the code that's commented out is where my problem is.

<?php
function uc_pngquote_quote($products, $details) {
   
$rate = 0;
   
$basic_charge = 0;

   
//get shipping info

   
$postal_code = $details['postal_code'];
   
$country = $details['country'];
   
$zone = $details['zone'];
   
//$deliverytype = $details['deliverytype'];
    //$deliverytype = variable_get('deliverytype','');

    //get order weight

   
$pkgweight = 0;
   
$pkgprice = 0;

if(
count($rules))
       
watchdog('Ubercart shipping', "No shipping rules selected for: Post code: '$postal_code', zone: '$zone', country '$country', total weight: $pkgweight kgs");

    if(
$rules) {
        foreach(
$rules as $rule) {
            switch (
$rule->flat_weight)    {
                case
'flat':
                   
$rate += $rule->rate;
                break;
                case
'weight':
                   
$units = $rule->units;
                   
$basic_charge = $rule->basic_charge;
                   
// We have to normalise the rate the same way we did the weight if this is to work.
                    //$rate += _uc_normalise_weight($rule->rate, $rule->units) * $pkgweight;
                   
                   
if ($deliverytype == t('Standard')) {
                     
$rate += _uc_normalise_weight($rule->rate, $rule->units) * $pkgweight;
                    }
                    else {
                     
$rate += ((_uc_normalise_weight($rule->rate, $rule->units) * $pkgweight) + $rule->basic_charge);
                    }
                   
                break;
            }
        }
       
$method = uc_pngquote_shipping_method();
       
$quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $rule->name);
    }

    return
$quotes;
}
?>

Posts: 2352
Joined: 08/07/2007
AdministratoreLiTe!

It sounds like you have the same problem as this guy:
http://www.ubercart.org/forum/development/6999/using_delivery_type_optio...

Posts: 7
Joined: 10/18/2008
Posts: 116
Joined: 04/23/2008

I was able to solve this by using 2 existing modules, and just a bug fix. I use ubercart 1.0 though:

1. "Weight quote" module in ubercart was enabled and then setup via admin/store/settings/quotes/methods/weightquote
[here I had default weight-based rate]

2. the world quote module: see my instructions here for the specific one I used and bug fix:
http://www.ubercart.org/forum/support/5775/shipping_quote_weight_and_geo...
[here I had a rule setup that does weight-based calcs but using an express rate - you can name it "Express Shipping"]

3. then I unhide shipping in: admin/store/settings/checkout/edit

So when you get to checkout, there will be a button that once pressed, will present both options to customer. See attachment.

4. Also make sure that the uc_products table has the correct weight and units for your products.

5. Also, I deleted all rows in uc_weightquote_products & uc_flatrate_products table since I want all products to pick up the default shipping.

Note that your own case may be different from mine... So do at your own risk...

If you still can't get it to work, send me a private message. I can help set it up on your site (for a fee as suggested...)

AttachmentSize
express_shipping.png3.98 KB