Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

disable a shipping module by weight


geoffwin

Recommended Posts

Hi and thanks for any advice

 

Using this information I tried something similar on a shipping module table (line 26)

 

$this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);

 

if ( ($this->enabled == true) && ($shipping_weight->info['total'] >= 3) ) {

$this->enabled = false;

}

 

I am trying to get the option to be hidden if the weight is over 3kg

 

Any suggestions on what to try or where I might be going wrong ? Basically the option will not switch to "false" if the weight is >=3 I have tried quite a few variations, hopefully it is something simple.

 

Geoff

Edited by geoffwin

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

Hi and thanks for any advice

 

Using this information I tried something similar on a shipping module table (line 26)

 

$this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);

 

if ( ($this->enabled == true) && ($shipping_weight->info['total'] >= 3) ) {

$this->enabled = false;

}

 

I am trying to get the option to be hidden if the weight is over 3kg

 

Any suggestions on what to try or where I might be going wrong ? Basically the option will not switch to "false" if the weight is >=3 I have tried quite a few variations, hopefully it is something simple.

 

Geoff

 

I have tried what I think to be every option - must be simpple ? here is the complete code. I want this shipping option to not be available greater then 3kg. I have the table set 3:10.50,10000:0 ,the table works fine just won't disappear greater then 3

 

any advice appreciated

 

Geoff

 

<?php

/*

$Id: table.php,v 1.27 2003/02/05 22:41:52 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

class table3 {

var $code, $title, $description, $icon, $enabled;

 

// class constructor

function table3() {

global $order;

 

$this->code = 'table3';

$this->title = MODULE_SHIPPING_TABLE3_TEXT_TITLE;

$this->description = MODULE_SHIPPING_TABLE3_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_TABLE3_SORT_ORDER;

$this->icon = DIR_WS_ICONS . 'auspost_express.gif';

$this->tax_class = MODULE_SHIPPING_TABLE3_TAX_CLASS;

 

 

$this->enabled = ((MODULE_SHIPPING_TABLE3_STATUS == 'True') ? true : false);

 

 

 

 

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE3_ZONE > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE3_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $order->delivery['zone_id']) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}

}

if ( ($this->enabled == true) && ($shipping_weight->info['total'] >= 3) ) {

$this->enabled = false;

}

}

 

// class methods

function quote($method = '') {

global $order, $cart, $shipping_weight, $shipping_num_boxes;

 

if (MODULE_SHIPPING_TABLE3_MODE == 'price') {

$order_total = $cart->show_total();

} else {

$order_total = $shipping_weight;

}

 

$table_cost = split("[:,]" , MODULE_SHIPPING_TABLE3_COST);

$size = sizeof($table_cost);

for ($i=0, $n=$size; $i<$n; $i+=2) {

if ($order_total <= $table_cost[$i]) {

$shipping = $table_cost[$i+1];

break;

}

}

 

if (MODULE_SHIPPING_TABLE3_MODE == 'weight') {

$shipping = $shipping * $shipping_num_boxes;

}

 

$this->quotes = array('id' => $this->code,

'module' => MODULE_SHIPPING_TABLE3_TEXT_TITLE,

'methods' => array(array('id' => $this->code,

'title' => MODULE_SHIPPING_TABLE3_TEXT_WAY,

'cost' => $shipping + MODULE_SHIPPING_TABLE3_HANDLING)));

 

if ($this->tax_class > 0) {

$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

}

 

if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

 

return $this->quotes;

}

 

function check() {

if (!isset($this->_check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TABLE3_STATUS'");

$this->_check = tep_db_num_rows($check_query);

}

return $this->_check;

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Table Method', 'MODULE_SHIPPING_TABLE3_STATUS', 'True', 'Do you want to offer table rate shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Table', 'MODULE_SHIPPING_TABLE3_COST', '25:8.50,50:5.50,10000:0.00', 'The shipping cost is based on the total cost or weight of items. Example: 25:8.50,50:5.50,etc.. Up to 25 charge 8.50, from there to 50 charge 5.50, etc', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Table Method', 'MODULE_SHIPPING_TABLE3_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TABLE3_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_TABLE3_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_TABLE3_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_TABLE3_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");

}

 

function remove() {

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

 

function keys() {

return array('MODULE_SHIPPING_TABLE3_STATUS', 'MODULE_SHIPPING_TABLE3_COST', 'MODULE_SHIPPING_TABLE3_MODE', 'MODULE_SHIPPING_TABLE3_HANDLING', 'MODULE_SHIPPING_TABLE3_TAX_CLASS', 'MODULE_SHIPPING_TABLE3_ZONE', 'MODULE_SHIPPING_TABLE3_SORT_ORDER');

}

}

?>

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

I have tried what I think to be every option - must be simpple ? here is the complete code. I want this shipping option to not be available greater then 3kg. I have the table set 3:10.50,10000:0 ,the table works fine just won't disappear greater then 3

 

any advice appreciated

 

Geoff

 

<?php

/*

  $Id: table.php,v 1.27 2003/02/05 22:41:52 hpdl Exp $

 

  osCommerce, Open Source E-Commerce Solutions

  http://www.oscommerce.com

 

  Copyright ? 2003 osCommerce

 

  Released under the GNU General Public License

*/

 

  class table3 {

    var $code, $title, $description, $icon, $enabled;

 

// class constructor

    function table3() {

      global $order;

 

...

...

?>

 

Adding $shipping_weight to the global declaration should do the trick otherwise the variable is not known within the module (example: zones.php).

Change:

// class constructor
function table3() {
global $order;

to

// class constructor
function table3() {
global $order, $shipping_weight;

 

HTH

Link to comment
Share on other sites

Adding $shipping_weight to the global declaration should do the trick otherwise the variable is not known within the module (example: zones.php).

Change:

// class constructor
function table3() {
global $order;

to

// class constructor
function table3() {
global $order, $shipping_weight;

 

HTH

 

thanks Howard but this did not work, the link in my first post related to disabling a payment option if over a certain amount from the Osc FAQ. This did not mention any change other then what I have done / adapted.

 

I was wondering if

 

if ( ($this->enabled == true) && ($shipping_weight->info['total'] >= 3) ) {

$this->enabled = false;

 

was actually using the correct information? ie is ($shipping_weight->info['total'] >= 3) actually asking for the weight of the order ?

 

I am still confused

 

Geoff

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

thanks Howard but this did not work, the link in my first post related to disabling a payment option if over a certain amount from the Osc FAQ. This did not mention any change other then what I have done / adapted.

 

I was wondering if

 

if ( ($this->enabled == true) && ($shipping_weight->info['total'] >= 3) ) {

$this->enabled = false;

 

was actually using the correct information? ie is ($shipping_weight->info['total'] >= 3) actually asking for the weight of the order ?

 

I am still confused

 

Geoff

 

Geoff,

 

If I am correct the $shipping_weight variable already contains the total weight for the products inside the cart so your if-construction should read:

if ( ($this->enabled == true) || ($shipping_weight >= 3) ) {
$this->enabled = false;

also you used an OR construction while I would think you would want to use an AND construction; if the module is enabled AND the weight is equal or more then 3 kg. then you disable the module afterall, otherwise just keep it enabled.

You can put a little test in your module by adding some echo's to see what the various variables values become.

IE. echo 'Value for info[total]= ' . $shipping_weight->info['total'];

echo 'Value for $shipping_weight= ' . $shipping_weight;

 

I find this easy sometimes to see if I am on the right track and to see if I am comparing the correct variables etc

 

Howard

Link to comment
Share on other sites

Geoff,

 

If I am correct the $shipping_weight variable already contains the total weight for the products inside the cart so your if-construction should read:

if ( ($this->enabled == true) || ($shipping_weight >= 3) ) {
$this->enabled = false;

also you used an OR construction while I would think you would want to use an AND construction; if the module is enabled AND the weight is equal or more then 3 kg. then you disable the module afterall, otherwise just keep it enabled.

You can put a little test in your module by adding some echo's to see what the various variables values become.

IE. echo 'Value for info[total]= ' . $shipping_weight->info['total'];

    echo 'Value for $shipping_weight= ' . $shipping_weight;

 

I find this easy sometimes to see if I am on the right track and to see if I am comparing the correct variables etc

 

Howard

 

thanks Howard

 

still not happening for me

when I put in the echoes I got empty responses back, so it appears that weight info is not in the module in a straight forward form.

 

This is starting to beat me, will have to give it a rest for a while.

 

thanks again

 

Geoff

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

thanks Howard

 

still not happening for me

when I put in the echoes I got empty responses back, so it appears that weight info is not in the module in a straight forward form.

 

This is starting to beat me, will have to give it a rest for a while.

 

thanks again

 

Geoff

 

You know what ?! I think it is in the wrong class method !

It should be here:

function quote($method = '') {

global $order, $cart, $shipping_weight, $shipping_num_boxes;

 

there the $shipping_weight is already defined and will be known. Remove it from

function table3() and move the IF to the function quote and try if this->enabled = false will work from there.

Link to comment
Share on other sites

this example using COD.php

You know what ?! I think it is in the wrong class method !

It should be here:

function quote($method = '') {

global $order, $cart, $shipping_weight, $shipping_num_boxes;

 

there the $shipping_weight is already defined and will be known. Remove it from

function table3() and move the IF to the function quote and try if this->enabled = false will work from there.

 

Still no go - this example using COD.php shows nothing complex, it must be something simple

 

Geoff

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

this example using COD.php

 

Still no go - this example using COD.php shows nothing complex, it must be something simple

 

Geoff

 

Damn, this is strange :huh:

It must be something simple indeed... I'll have to create a test later today with your table settings to see what is happening and why. Could you at least see the $shipping_weight with a value ? How have you defined the weight with the products; like 0.5, 1, 2 etc. for half a kilogram, 1 kilogram, 2 kilogram etc. ?

We'll find that little bugger :D

Link to comment
Share on other sites

Damn, this is strange  :huh:

It must be something simple indeed... I'll have to create a test later today with your table settings to see what is happening and why. Could you at least see the $shipping_weight with a value ? How have you defined the weight with the products; like 0.5, 1, 2 etc. for half a kilogram, 1 kilogram, 2 kilogram etc. ?

We'll find that little bugger  :D

 

I have set the table as 3:10.50,10000:0.00

My goods are set up in kg units eg 1, 2.45, 3 etc

the table by itself works OK

 

eg I buy 1 unit at 2.45 the shipping appears at $10.50, I add another unit to the order and(as the weight is > 3kg ie 4.9) the shipping is $0.00

 

when I change

 

$this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);

 

 

to

 

$this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);

 

if ( ($this->enabled == true) && ($shipping_weight->info['total'] >= 3) ) {

$this->enabled = false;

}

 

the table will still work and this change appears to be ignored (as explained in the link for COD.php)

 

there is a 'weight' variable that I have tried but the result is the same ie the same as the 'total' variable

 

A confusing anomaly is if I make the ($shipping_weight->info['total'] <= 3)

 

the option disappears, this makes me think it is calling a value that is not weight.

 

Anyway would still appreciate any help.

 

Geoff

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

I have set the table as 3:10.50,10000:0.00

My goods are set up in kg units eg 1, 2.45, 3 etc

the table by itself works OK

 

eg I buy 1 unit at 2.45 the shipping appears at $10.50, I add another unit to the order and(as the weight is > 3kg ie 4.9) the shipping is $0.00

 

when I change

 

$this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);

to

 

$this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);

 

if ( ($this->enabled == true) && ($shipping_weight->info['total'] >= 3) ) {

$this->enabled = false;

}

 

the table will still work and this change appears to be ignored (as explained in the link for COD.php)

 

there is a 'weight' variable that I have tried but the result is the same ie the same as the 'total' variable

 

A confusing anomaly is if I make the ($shipping_weight->info['total'] <= 3)

 

the option disappears, this makes me think it is calling a value that is not weight.

 

Anyway would still appreciate any help.

 

Geoff

 

So to be sure: if I deinstall my zones modules, install the default osC table based shipping module with only one zone and put in your values I have a valid test environment for your situation ?!

Link to comment
Share on other sites

So to be sure: if I deinstall my zones modules, install the default osC table based shipping module with only one zone and put in your values I have a valid test environment for your situation ?!

 

That is correct to my knowledge

 

I have no zones settings within the shipping module area

 

I have set up a zone using Australian States, the response I get from the changes to the tables3.php as explained occurs whether there are zones selected or not.

 

Geoff

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

That is correct to my knowledge

 

I have no zones settings within the shipping module area

 

I have set up a zone using Australian States, the response I get from the changes to the tables3.php as explained occurs whether there are zones selected or not.

 

Geoff

 

Okay, then that should be clear. I hope I can find something useful for you so until laterz !

 

Howard

Link to comment
Share on other sites

great

 

really appreciate the help

 

Geoff

 

Geoff,

 

Still very much learning PHP and syntax myself but here is how it should work.

First, info['total'] returns the total price and not the total weight so it can't be used.

I found no way to get the total weight within the first class constructor so I think it is only calculated afterwards and so only known within the class function quote($method = ''). It doesn't matter as you can achieve it even easier over there, if possible at all inside the class constructor.

Anyhow, add

	if ( ($this->enabled == true) && ($shipping_weight >= 3) ) {
$this->enabled = false;
return;
}

just above

      return $this->quotes;
   }

The 'return;' is essential here otherwise the '$this->quotes' will still be returned and keep the module visible despite the shipping weight going over 3 kg.

I tested this and it works smoothly as far as I can tell.

 

Grtz.

Howard

Link to comment
Share on other sites

Geoff,

 

Still very much learning PHP and syntax myself but here is how it should work.

First, info['total'] returns the total price and not the total weight so it can't be used.

I found no way to get the total weight within the first class constructor so I think it is only calculated afterwards and so only known within the class function quote($method = ''). It doesn't matter as you can achieve it even easier over there, if possible at all inside the class constructor.

Anyhow, add

	if ( ($this->enabled == true) && ($shipping_weight >= 3) ) {
$this->enabled = false;
return;
}

just above

 ? ? ?return $this->quotes;
? ?}

The 'return;' is essential here otherwise the '$this->quotes' will still be returned and keep the module visible despite the shipping weight going over 3 kg.

I tested this and it works smoothly as far as I can tell.

 

Grtz.

Howard

 

Thanks Howard

 

have tried this and so far it is working, really appreciate the effort you put in to help.

 

In regards to info ["total'] this is what I thought, I was trying to use the 'weight' in the module. I must do more reading / work in php as I really have no idea what is happening.

 

I asked this question in another thread and suggested my start point - it was reported that it was working fine for them and doing what it was meant to do - but they have not returned since hence this thread!

 

Again thanks - I know who to call in future :-))

 

all the best

 

Geoff

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

Thanks Howard

 

have tried this and so far it is working, really appreciate the effort you put in to help.

 

In regards to info ["total'] this is what I thought, I was trying to use the 'weight' in the module. I must do more reading / work in php as I really have no idea what is happening.

 

I asked this question in another thread and suggested my start point - it was reported that it was working fine for them and doing what it was meant to do - but they have not returned since hence this thread!

 

Again thanks - I know who to call in future :-))

 

all the best

 

Geoff

 

Hello Geoff,

 

I am glad to hear it worked ! I still have to learn a lot about osC myself and this helps me too for a better understanding. If you go back to the base, checkout_shipping.php, you will see that inside this file the order.php is called before getting the total shipping weight and going through all the shipping modules which someone has installed. Inside the order.php you will find that the info array is filled but not with a weight value so there is no info['weight'] in existence.

There might be a way to use the table shipping class constructor, which would be the better place for this, after all but for now this is a solid enough solution I guess.

 

All the best to you too and good luck with your shop !

 

Howard

Link to comment
Share on other sites

Ok,

 

I'm still very new at all this stuff, but what would be the complete hack to this.

 

I've got the Canada Post shipping Module working beautifully, but there are some items I have that could definatly be shipped alot cheaper than what I have to charge, since the server only recognizes business rates and regular mail is alway 6 bucks +, even if the item is only .02 kilos.

 

Now, I got the table rate going, to give my customers another option, but I want it to disapear once it hits .54 kilos and over, so my customers will ONLY see the Canada Post rate.

 

What do I gotta do guys, I'm scratching my head over your fine work.

 

Geof.

Link to comment
Share on other sites

Ok,

 

I'm still very new at all this stuff, but what would be the complete hack to this.

 

I've got the Canada Post shipping Module working beautifully, but there are some items I have that could definatly be shipped alot cheaper than what I have to charge, since the server only recognizes business rates and regular mail is alway 6 bucks +, even if the item is only .02 kilos.

 

Now, I got the table rate going, to give my customers another option, but I want it to disapear once it hits .54 kilos and over, so my customers will ONLY see the Canada Post rate.

 

What do I gotta do guys, I'm scratching my head over your fine work.

 

Geof.

 

Well, that shouldn't be different as the above. Just add the same to your table rate module and adept it to disspear when the total weight goes over .54 kg. instead of 3 kg.

Link to comment
Share on other sites

Well, that shouldn't be different as the above. Just add the same to your table rate module and adept it to disspear when the total weight goes over .54 kg. instead of 3 kg.

 

So all I have to do is add this:

 

if ( ($this->enabled == true) && ($shipping_weight >= .54) ) {
$this->enabled = false;
return;
}

 

before, or above this:?

 

    return $this->quotes;
  }

 

?

 

Geof.

Link to comment
Share on other sites

It works great, thank you both for your work on this.

 

Only if it was an option within' the administrator interface.

 

Thanks Again!

 

Geof.

 

 

All Howard - he turned on the light, I was just fumbling in the dark

:-)

 

Geoff

Geoff

 

Telegraph Point 2441

Australia

Link to comment
Share on other sites

  • 1 year later...

Hello,

 

I'm a newbie and would greatly appreciate your help with what I hope is a simple question. I've reviewed the forum thoroughly for a solution to my question but have not found one.

 

Is there any way to apply a similar code change approach but, instead, revise it to "disable a shipping method (or only use a shipping method) if product added to shopping cart is in category number 3"?

 

I'd like to customize the Fedex Freight 0.5 contribution to only show that shipping method if the product added to the shopping cart is in the heaviest weight products within category 3.

 

Thank you in advance for your help.

 

Best regards,

 

Dick

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...