12 replies [Last post]
Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
Was this information Helpful?

Hi all,

I have been adding alot of flatrates for shipping. All of them based on Weight and Country. All of the flatrates I already made are for packages with kind of no restriction in size. Now: the post service provides other and lower prices as well for packages (big envelopes) that are maximum 23x35x3 centimeters. I was wondering how I could add this to my flatrates. If I could bring together all of the products that are rated 'small' somehow, that would be enough. In a product page there is the possibility to add dimensions, but this information does not seem able to be used to calculate flatrates.

I am not going to select all the different products myself per shipping quote. I don't want my client to go edit the shipping quote settings all the time. That wouldn't be user friendly.

I really hope there is a sollution for this as it would save the customers alot of money.

All help is very appreciated.
Thanks in advance.
Cheers,
Danny

Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_

Anyone? ...

Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_

I hope I haven't been rude or anything, as I haven't received any feedback on this. If I was, I apologize. This flatrate based on dimensions, would decide the success of the online store. That's why I want to know so bad if there is a sollution for this. But I don't get a yes or a no. I've used search, I've used google, but I can't find any answer for this. The closest answer I found is 'build it yourself'. But I'm not a module developer.

Any help on this is highly appreciated...

Cheers,
Danny

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: _

If that's the case, then it sounds like you need to hire someone to develop what you need. I haven't put a "no" response here mostly because someone might have written such a thing and I didn't know it.

Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_

Thanks for your reply, Lyle. I'm not a developer, but I might take a look to see if I'm able to tweak something a bit. If I succeed, I will give it back to the community.

Do you have any quick hints or documentation for this? I've read something about workflow-nt, but that's only for UC1, no? I'm using UC2. I've tweaked an existing module before, but this is not going to be a module I guess. Just another 'action'. Where would I be able to find the other conditional actions in the code?

Cheers,
Danny

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: _

For the most part, the definitions of the conditions and actions are in the modules' *.ca.inc files. uc_order.ca.inc will probably be the most useful for you to look at since it has the weight condition. I think that's the one most like what you need. Specifically, look at uc_order_condition_products_weight(), uc_order_condition_products_weight_form(), and the part of uc_order_ca_condition() that's specific to that function.

You can either create a whole new module for it, or post it as a patch (see http://drupal.org/patch for info on that) to uc_order.ca.inc.

sandroz's picture
Offline
Joined: 08/05/2009
Juice: 25
Re: Re: _

Hi, would be interested in this module/patch too... Think its important to have a condition wich can check the total order dimension....

Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_

I didn't have the time yet as I had my brother coming over for a holliday/visit. He left yesterday so I have time to work on it now. I'm not a developer and i kinda have to learn to program drupal applications from scratch. So any help is very welcome. I'm going to research this as far as possible, but if someone wants to take this over from me, please let me know. My current financial situation does not allow me to research very much.

Cheers,
Danny

Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_

My current status on this little project:

In uc_order.ca.inc I have added:

In function uc_order_ca_condition() :

<?php
  $conditions
['uc_order_condition_products_size'] = array(
   
'#title' => t("Check an order's size"),
   
'#category' => t('Order: Product'),
   
'#description' => t('Determines if the order has the specified size, possibly counting only a certain type of product.'),
   
'#callback' => 'uc_order_condition_products_size',
   
'#arguments' => array(
     
'order' => $order_arg,
    ),
  );
?>

separate:

<?php
function uc_order_condition_products_size_form($form_state, $settings = array()) {
 
$options = array('all' => t('- All products -'));
 
$result = db_query("SELECT nid, model FROM {uc_products}");
  while (
$product = db_fetch_object($result)) {
   
$options[$product->nid] = $product->model;
  }
 
$form['products'] = array('#type' => 'select',
   
'#title' => t('Products'),
   
'#options' => $options,
   
'#default_value' => $settings['products'],
   
'#description' => check_plain(t('Selecting "- All products -" will override any other selections and returns the total number of products in the order.')),
   
'#multiple' => TRUE,
  );
 
$form['length_units'] = array('#type' => 'select',
   
'#title' => t('Unit of measurement'),
   
'#default_value' => $settings['length_units'] ? $settings['length_units'] : variable_get('uc_length_unit', 'cm'),
   
'#options' => array(
     
'in' => t('Inches'),
     
'ft' => t('Feet'),
     
'cm' => t('Centimeters'),
     
'mm' => t('Millimeters'),
    ),
  );
 
$form['dimensions'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('Dimensions'),
   
'#description' => t('Physical dimensions of the package.'),
  );
 
$form['dimensions']['product_length_value'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Product length value'),
   
'#default_value' => $settings['dimensions']['product_length_value'],
   
'#size' => 16,
  );
 
$form['dimensions']['product_width_value'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Product width value'),
   
'#default_value' => $settings['dimensions']['product_width_value'],
   
'#size' => 16,
  );
 
$form['dimensions']['product_height_value'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Product height value'),
   
'#default_value' => $settings['dimensions']['product_height_value'],
   
'#size' => 16,
  );

 

$options = array(
   
'less' => t('Total is less than specified value.'),
   
'less_equal' => t('Total is less than or equal to specified value.'),
   
'equal' => t('Total is equal to specified value.'),
   
'greater_equal' => t('Total is greater than or equal to specified value.'),
   
'greater' => t('Total is greater than specified value.'),
  );
 
$form['product_weight_comparison'] = array(
   
'#type' => 'radios',
   
'#title' => t('Product count comparison type'),
   
'#options' => $options,
   
'#default_value' => isset($settings['product_weight_comparison']) ? $settings['product_weight_comparison'] : 'greater_equal',
  );

  return

$form;
}
?>

The only and difficult part remaining is the calculation in "function uc_order_condition_products_size". There's lots of stuff in the 'weight'-equivalent that I don't understand. And the size function will be more complicated.
For example: you can't expect that the best sollution is to compare the length of the package with the length of the product. Sometimes if you compare package-length with product-width etc, it might fit better than the straightforward length-length comparison.

Plus: adding products will be difficult. How do you find the best addition of 3dimensional shapes? For me this is not really required, but I guess others will need it. I think it is possible, but my brains are not built for that kind of mathematics and therefore will not comprehend it... Smiling

Any help is welcome here.

Cheers,
Danny

sandroz's picture
Offline
Joined: 08/05/2009
Juice: 25
Thanks!

Thanks for sharing the code. Will try that for me.

I dont need three dimensions, only the thickness of the order total...

Best Regards
Sandro

Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_

It's not working yet, but this is my code. It's pretty ugly, but that's because i'm a designer and not a developer.
I feel that the form is correct and working, but it's the actual calculation that goes wrong. My goal here is that whenever all the products (individually) fit inside(or whatever selected) the given dimensions, then I want to return a TRUE. Else a FALSE. For me it is not important if the addition of the individual dimensions of the products fit the given size.

If you are a developer and you see immediately a big error, please post it here. I'm kinda stuck. Does anyone have hints on how to debug these functions?

Cheers,
Danny

<?php
function uc_order_condition_products_size($order, $settings) {
 
//$totals = array('all' => 0);
  //$total = 0;
 
$result = array();
 
  foreach (
$order->products as $product) {
   
$unit_conversion = uc_length_conversion($product->length_units, $settings['length_units']);
   
   
$productSize = array();
   
$productSize[] = $product->length * $unit_conversion;
   
$productSize[] = $product->width * $unit_conversion;
   
$productSize[] = $product->height * $unit_conversion;
   
rsort($productSize);
      
   
$packageSize = array();
   
$packageSize[] = $settings['product_length_value'];
   
$packageSize[] = $settings['product_width_value'];
   
$packageSize[] = $settings['product_height_value'];
   
rsort($packageSize);
   
   
//$totals['all'] += $product->qty * $product->weight * $unit_conversion;
    //$totals[$product->model] = $product->qty * $product->weight * $unit_conversion;
 

 
 

switch ($settings['product_size_comparison']) {
    case
'less':
      if((
$productSize[0] < $packageSize[0]) and  
          (
$productSize[1] < $packageSize[1]) and
          (
$productSize[2] < $packageSize[2])){
     
$result[] = true;
      }
      else {
     
$result[] =false;
      }
    case
'less_equal':
      if((
$productSize[0] <= $packageSize[0]) and
        (
$productSize[1] <= $packageSize[1]) and
        (
$productSize[2] <= $packageSize[2])) {
     
$result[] = true;
      }
      else {
     
$result[] =false;
      }
    case
'equal':
      if((
$productSize[0] == $packageSize[0]) and
        (
$productSize[1] == $packageSize[1]) and
        (
$productSize[2] == $packageSize[2])) {
     
$result[] = true;
      }
      else {
     
$result[] =false;
      }
    case
'greater_equal':
      if((
$productSize[0] >= $packageSize[0]) and
        (
$productSize[1] >= $packageSize[1]) and
        (
$productSize[2] >= $packageSize[2])) {
     
$result[] = true;
      }
      else {
     
$result[] =false;
      }
    case
'greater':
      if((
$productSize[0] > $packageSize[0]) and
        (
$productSize[1] > $packageSize[1]) and
        (
$productSize[2] > $packageSize[2])) {
     
$result[] = true;
      }
      else {
     
$result[] =false;
      }
  }
 
  }
 
  if(
in_array(false, $result)) {
      return
false;
  }
  else{
      return
true;
  }
 
}

function

uc_order_condition_products_size_form($form_state, $settings = array()) {
 
$options = array('all' => t('- All products -'));
 
$result = db_query("SELECT nid, model FROM {uc_products}");
  while (
$product = db_fetch_object($result)) {
   
$options[$product->nid] = $product->model;
  }
 
$form['products'] = array('#type' => 'select',
   
'#title' => t('Products'),
   
'#options' => $options,
   
'#default_value' => $settings['products'],
   
'#description' => check_plain(t('Selecting "- All products -" will override any other selections and returns the total number of products in the order.')),
   
'#multiple' => TRUE,
  );
 
$form['length_units'] = array('#type' => 'select',
   
'#title' => t('Unit of measurement'),
   
'#default_value' => $settings['length_units'] ? $settings['length_units'] : variable_get('uc_length_unit', 'cm'),
   
'#options' => array(
     
'in' => t('Inches'),
     
'ft' => t('Feet'),
     
'cm' => t('Centimeters'),
     
'mm' => t('Millimeters'),
    ),
  );
 
$form['dimensions'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('Dimensions'),
   
'#description' => t('Physical dimensions of the package.'),
  );
 
$form['dimensions']['product_length_value'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Product length value'),
   
'#default_value' => $settings['dimensions']['product_length_value'],
   
'#size' => 16,
  );
 
$form['dimensions']['product_width_value'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Product width value'),
   
'#default_value' => $settings['dimensions']['product_width_value'],
   
'#size' => 16,
  );
 
$form['dimensions']['product_height_value'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Product height value'),
   
'#default_value' => $settings['dimensions']['product_height_value'],
   
'#size' => 16,
  );

 

$options = array(
   
'less' => t('Total is less than specified value.'),
   
'less_equal' => t('Total is less than or equal to specified value.'),
   
'equal' => t('Total is equal to specified value.'),
   
'greater_equal' => t('Total is greater than or equal to specified value.'),
   
'greater' => t('Total is greater than specified value.'),
  );
 
$form['product_size_comparison'] = array(
   
'#type' => 'radios',
   
'#title' => t('Product count comparison type'),
   
'#options' => $options,
   
'#default_value' => isset($settings['product_size_comparison']) ? $settings['product_size_comparison'] : 'greater_equal',
  );

  return

$form;
}
?>
Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_

As I'm stuck with this one, I tried to do it another way. Through a checkbox like the 'shippable' option. I'm also stuck with that one. Any help there is also very appreciated. http://www.ubercart.org/forum/development/12847/checkbox_product_shippable

Cheers,
Danny

Danny_Joris's picture
Offline
Joined: 05/09/2009
Juice: 199
_