5 replies [Last post]
gilave's picture
Offline
Joined: 09/18/2008
Juice: 16
Was this information Helpful?

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;
}
?>
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: How to reference checkout pane data for shipping quote calcu

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

freddy031082's picture
Offline
Joined: 10/18/2008
Juice: 15
Re: Re: How to reference checkout pane data for shipping quote c
zeezhao's picture
Offline
Joined: 04/23/2008
Juice: 969
Re: How to reference checkout pane data for shipping quote calcu

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.png 3.98 KB
Mog
Mog's picture
Offline
Internationalizationizer
Joined: 08/16/2007
Juice: 160
Hi, I "reup" this problem

Hi,

I "reup" this problem because i got same thing i want to do on ubercart 2.x drupal 6.x:
add a checkout pane depending on wich shipping quote is selected.

So i need to know how i can get shipping quote value without modifying uc_payment.js (on render_line_items()).

I try to work with Drupal.behaviors.getQuotes() to add my action when quote is request and selected but i can't have something good;

if someone have an idea ?

Regards;
Mog;

Mog
Mog's picture
Offline
Internationalizationizer
Joined: 08/16/2007
Juice: 160
Re: Hi, I "reup" this problem

Ok, sorry i find solution ...
Perhaps it could help someone.

I wasn't very "aware" about Drupal.behaviors, all i need to do is adding js like this one :

Drupal.behaviors.myBehavior = function (context) {
  $("#quote").find("input:radio").click(function() {
    var checkedvalue = $(this).val();
    if (window.set_line_item) {

      // do something, here is a sample, show my checkout pane if shipping quote is flatrate
      if (checkedvalue && checkedvalue.substr(0, 8 ) == "flatrate") {
        $("#myModule-pane").show();
      } else {
        $("#myModule-pane").hide();
      }

    }
  });
};

Regards.
Mog.