Jump to content
Sign in to follow this  
xswiftyx

Zone rates - only want to it to show over 7KGs

Recommended Posts

As the title says. Zone rates is set up perfect for UK - Europe - and rest of the world. But i only want to it appear over when the products bought is over 7KGs.

Tried adding:

 

if ($total_weight < 7) {	  // If total ship weight is less than 7.00Kg do not show this shipping method
		  $this->enabled = false;	// Anything under 7Kg its not economically wise to use this method (Royal Mail recommended)
	 }						// To remove this 7.00Kg limit, simply delete these 3 lines

 

Under

 

  // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
  $this->num_zones = 3;

 

On line 110 but then it doesnt show at all. Anyone got any Idea's? must be something simple

Share this post


Link to post
Share on other sites

I'm a noob my self but have you tried the below

From my very limited knowledge this is saying when more then 7kg show this method. I have tried putting limits on the airmail so it dosn't show over a given weight but end up getting error t_function expected so i'm a bit lost lol. I must be missing some other bit of code to go with it but can't figure out what.

 

 

if ($total_weight > 7) {

$this->enabled = true;

}

Share this post


Link to post
Share on other sites

Yes tried it that way round too. I have the UK shipping contribution installed and works fine. This code is used in 1st class recorded for example where it will not show it after 3KG - that work fine. Could just edit that but need it for 3 zones

Share this post


Link to post
Share on other sites

Edit the follolwing code to what you like - seems to work :)

 

<?php
/*   $Id: Royal Mail First Class Recorded by Stuart Newton 21 August 2006
 Demo: http://www.almatcomputers.co.uk
 Rates: .1:1.68,.25:1.95,.5:2.38,.75:2.88,1:3.38,1.25:5.42,1.5:6.27,1.75:7.12,2:7.97,2.25:8.82,2.5:9.67,2.75:10.52,3:11.37
 Limits Applied: 3.00Kg orders over this value will not be shown this method.
*/

 class rmfirstrec {
var $code, $title, $description, $enabled, $num_zones;

// class constructor
function rmfirstrec() {
global $order, $total_weight;
  $this->code = 'rmfirstrec';
  $this->title = MODULE_SHIPPING_RMFIRSTREC_TEXT_TITLE;
  $this->description = MODULE_SHIPPING_RMFIRSTREC_TEXT_DESCRIPTION;
  $this->sort_order = MODULE_SHIPPING_RMFIRSTREC_SORT_ORDER;
  $this->icon = DIR_WS_ICONS . 'shipping_rmukrec.gif'; // upload icon to catalog/images/icon directory
  $this->tax_class = MODULE_SHIPPING_RMFIRSTREC_TAX_CLASS;
  $this->enabled = ((MODULE_SHIPPING_RMFIRSTREC_STATUS == 'True') ? true : false);
  $this->num_zones = 1;

	 if ($total_weight > 3) {	 	// If total ship weight is over 3.00Kg do not show this shipping method
		  $this->enabled = false;	// Anything over 3Kg its not economically wise to use this method
	 }							 	// To remove this 3.00Kg limit, simply delete these 3 lines.

	 if ($order->info['total'] > 60)  {	 // If total ship cart price is over £32 do not show this shipping method
			$this->enabled = false;			// Royal Mail does not offer insurance for items over £32.00
	}										// To remove this £32.00 limit, simply delete these 3 lines

}

// class methods
function quote($method = '') {
global $order, $shipping_weight, $shipping_num_boxes;
  $dest_country = $order->delivery['country']['iso_code_2'];
  $dest_zone = 0;
  $error = false;
	  if ($order->delivery['country']['iso_code_2'] == 'GB')  {  // Only UK Customers to see shipping method. Hide everbody else.
	  for ($i=1; $i<=$this->num_zones; $i++) {
	  $countries_table = constant('MODULE_SHIPPING_RMFIRSTREC_COUNTRIES_' . $i);
	  $country_zones = split("[,]", $countries_table);
	  if (in_array($dest_country, $country_zones)) {
		$dest_zone = $i;
		break;
	  }
	}

  if ($dest_zone == 0) {
	$error = true;
  } else {
	$shipping = -1;
	$zones_cost = constant('MODULE_SHIPPING_RMFIRSTREC_COST_' . $dest_zone);

	$zones_table = split("[:,]" , $zones_cost);
	$size = sizeof($zones_table);
	for ($i=0; $i<$size; $i+=2) {
	  if ($shipping_weight <= $zones_table[$i]) {
		$shipping = $zones_table[$i+1];
		if(tep_not_null($method) )
		// Text shown on Checkout_Confirmation
		$shipping_method = ''; // Leaving this entry blank causes only the shipping title to show i.e Royal Mail 1st Class Rec 	  
		else
		// Text shown on Checkout_shipping -  Delivery Weight : 0.7 Kg's (Ships normally within 1 to 3 days)
		$shipping_method = MODULE_SHIPPING_RMFIRSTREC_TEXT_WAY . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_RMFIRSTREC_TEXT_UNITS . ' ' . MODULE_SHIPPING_RMFIRSTREC_DELIVERY_TIMES; 
		break;
	  }
	}

	if ($shipping == -1) {
	  $shipping_cost = 0;
	  $shipping_method = MODULE_SHIPPING_RMFIRSTREC_UNDEFINED_RATE;
	} else {
	  $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_RMFIRSTREC_HANDLING_' . $dest_zone);
	}
  }

  $this->quotes = array('id' => $this->code,
						'module' => MODULE_SHIPPING_RMFIRSTREC_TEXT_TITLE,
						'methods' => array(array('id' => $this->code,
												 'title' => $shipping_method,
												 'cost' => $shipping_cost)));

  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);

  if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_RMFIRSTREC_INVALID_ZONE;

  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_RMFIRSTREC_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 RM First Class Recorded Postage', 'MODULE_SHIPPING_RMFIRSTREC_STATUS', 'True', 'Do you want to offer this shipping option?', '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, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_RMFIRSTREC_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, date_added) values ('Sort Order', 'MODULE_SHIPPING_RMFIRSTREC_SORT_ORDER', '3', 'Sort order of display (1 shown first 99 etc shown last to customer)', '6', '0', now())");

  for ($i = 1; $i <= $this->num_zones; $i++) {
	$default_countries = '';
	if ($i == 1) {
	  $default_countries = 'GB';
	}
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('ISO Country Code', 'MODULE_SHIPPING_RMFIRSTREC_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Enter the two digit ISO code for which this shipping method applies too. (Default: GB)', '6', '0', now())");

  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('RM First Class Recorded Rates', 'MODULE_SHIPPING_RMFIRSTREC_COST_" . $i ."', '.1:1.68,.25:1.95,.5:2.38,.75:2.88,1:3.38,1.25:5.42,1.5:6.27,1.75:7.12,2:7.97,2.25:8.82,2.5:9.67,2.75:10.52,3:11.37', 'Enter values upto 5,2 decimal places. (12345.67) Example: .1:1,.25:1.27 - Weights less than or equal to 0.1Kg would cost £1.00, Weights less than or equal to 0.25g but more than 0.1Kg will cost £1.27. Do not enter KG or £ symbols.', '6', '0', now())");
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Packaging / Handling Fee', 'MODULE_SHIPPING_RMFIRSTREC_HANDLING_" . $i."', '0', 'If you want to add extra costs to customers for jiffy bags etc, the cost can be entered below (eg enter 1.50 for a value of £1.50)', '6', '0', now())");
  }
}

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

function keys() {
  $keys = array('MODULE_SHIPPING_RMFIRSTREC_STATUS', 'MODULE_SHIPPING_RMFIRSTREC_TAX_CLASS', 'MODULE_SHIPPING_RMFIRSTREC_SORT_ORDER');

  for ($i=1; $i<=$this->num_zones; $i++) {
	$keys[] = 'MODULE_SHIPPING_RMFIRSTREC_COUNTRIES_' . $i;
	$keys[] = 'MODULE_SHIPPING_RMFIRSTREC_COST_' . $i;
	$keys[] = 'MODULE_SHIPPING_RMFIRSTREC_HANDLING_' . $i;
  }

  return $keys;
}
 }
?>

Share this post


Link to post
Share on other sites

Changed my mind! This will work with 1 zone. not more. Anyone know how to make this work with more than 1 zone? Its more than just changing the number from 1 to 3

Share this post


Link to post
Share on other sites
Changed my mind! This will work with 1 zone. not more. Anyone know how to make this work with more than 1 zone? Its more than just changing the number from 1 to 3

 

You need to remove the shipping module before changing the number of zones inside the file. Otherwise it won't create the proper database entries.

Share this post


Link to post
Share on other sites

Like i said above i can't get a limit to work on shipping with more than 1 zone (airmail). I'm sure some one out there has done it because having a huge shipping cost for shipping over a given weight is hardly a solution lol. I my self also need a limit on the cost that i will send airmail also!!!!

 

I'm going to fiddle with code some more to see if i can get it to work and not throw up an error. I do not know anything about PHP but my brain works logicaly and i might figure some thing out!

Share this post


Link to post
Share on other sites
Tried that just throws up the same error "Parse error: syntax error, unexpected ';', expecting T_FUNCTION in airmailrecorded.php"

Context please....

Share this post


Link to post
Share on other sites

Tried using $shipping_weight instead of $total_weight

 

So i tried the following airmailrecorded.php to try put a limit on wieght and it just gives you "Parse error: syntax error, unexpected ';', expecting T_FUNCTION in airmailrecorded.php" in the OSC admin for the shipping module, but works fine again when u take out the "if ($shipping_weight > 2) { $this->enabled = false;"

 

class airmailsigned {

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

 

// class constructor

function airmailsigned() {

global $order;

$this->code = 'airmailsigned';

$this->title = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_TITLE;

$this->description = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER;

$this->icon = DIR_WS_ICONS . 'shipping_airmail.gif'; // upload icon to catalog/images/icon directory

$this->tax_class = MODULE_SHIPPING_AIRMAILSIGNED_TAX_CLASS;

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

if ($order->delivery['country']['iso_code_2'] == 'GB') {

$this->enabled = false;

 

if ($shipping_weight > 2) {

$this->enabled = false;

 

}

// CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED

$this->num_zones = 2;

}

 

// class methods

function quote($method = '') {

global $order, $shipping_weight, $shipping_num_boxes;

 

$dest_country = $order->delivery['country']['iso_code_2'];

$dest_zone = 0;

$error = false;

for ($i=1; $i<=$this->num_zones; $i++) {

$countries_table = constant('MODULE_SHIPPING_AIRMAILSIGNED_COUNTRIES_' . $i);

$country_zones = split("[,]", $countries_table);

if (in_array($dest_country, $country_zones)) {

$dest_zone = $i;

break;

}

}

 

// elari - Added to select default country if not in listing

if ($dest_zone == 0) {

$dest_zone = $this->num_zones; // the zone is the lastest zone avalaible

}

// elari - Added to select default country if not in listing

if ($dest_zone == 0) {

$error = true; // this can no more achieve since by default the value is set to the max number of zones

} else {

$shipping = -1;

$zones_cost = constant('MODULE_SHIPPING_AIRMAILSIGNED_COST_' . $dest_zone);

 

$zones_table = split("[:,]" , $zones_cost);

$size = sizeof($zones_table);

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

if ($shipping_weight <= $zones_table[$i]) {

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

if(tep_not_null($method) )

// Text shown on Checkout_Confirmation

$shipping_method = ''; // Leaving this entry blank causes only the shipping title to show i.e Royal Mail 1st Class Rec

else

// Text shown on Checkout_shipping - Delivery Weight : 0.7 Kg's (Ships normally within 1 to 3 days)

$shipping_method = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_WAY . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_AIRMAILSIGNED_TEXT_UNITS . ' ' . MODULE_SHIPPING_AIRMAILSIGNED_DELIVERY_TIMES;

if ($shipping_num_boxes > 1) {

$shipping_method .= $shipping_num_boxes . 'x ';

}

break;

}

}

 

if ($shipping == -1) {

$shipping_cost = 0;

$shipping_method = MODULE_SHIPPING_AIRMAILSIGNED_UNDEFINED_RATE;

} else {

$shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_AIRMAILSIGNED_HANDLING_' . $dest_zone);

}

}

// I want to add VAT to European purchases

// If I add 1.175* at the start of line 183, then it works and adds 17.5%, but to ALL Zones

// How do I make it only apply to Zone 1 below - viz. ($i == 2)

// The following doesn't work either, but just leaving line 190 works as before - to ALL zones

// if ($i == 2) {

// $shipping_cost = $shipping_cost*1.175;

// }

 

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

'module' => MODULE_SHIPPING_AIRMAILSIGNED_TEXT_TITLE,

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

'title' => $shipping_method,

'cost' => $shipping_cost)));

 

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);

 

if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_AIRMAILSIGNED_INVALID_ZONE;

 

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_AIRMAILSIGNED_STATUS'");

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

}

return $this->_check;

}

 

// elari - Added to select default country if not in listing

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 Zones Method', 'MODULE_SHIPPING_AIRMAILSIGNED_STATUS', 'True', 'Do you want to offer zone 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, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_AIRMAILSIGNED_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, date_added) values ('Sort Order', 'MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER', '10', 'Sort order of display.', '6', '0', now())");

for ($i = 1; $i <= $this->num_zones; $i++) {

$default_countries = '';

if ($i == 1) {

$default_countries = 'AL,AD,AM,AT,AZ,BY,BE,BA,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GI,GR,GL,HU,IS,IE,I

T,KZ,KG,LV,LI,LT,LU,MK,MT,MD,MC,NL,NO,PL,PT,RO,RU,SM,SK,SI,ES,SE,CH,TJ,TR,TM,UA,U

Z,VA';

//Airmail Rates for Europe at April 2007: Small packets to 2KG and printed Papers to 10KG (2 packets)

$shipping_table = '.1:1.24,.12:1.36,.14:1.50,.16:1.63,.18:1.77,.2:1.90,.22:2.03,.24:2.15,.26:2.

28,.28:2.39,.3:2.51,.4:3.06,.5:3.61,.6:4.11,.7:4.61,.8:5.11,.9:5.61,1:6.11,1.1:6.

61,1.2:7.11,1.3:7.61,1.4:8.11,1.5:8.61,1.6:9.11,1.7:9.61,1.8:10.11,1.9:10.61,2:11

.11,40:199';

}

if ($i == 2) {

$default_countries = 'All Others'; // this must be the lastest zone

// Airmail Rates for Rest of World at April 2007: Small packets to 2KG and printed Papers to 10KG (2 packets)

$shipping_table = '.1:1.64,.12:1.87,.14:2.10,.16:2.33,.18:2.56,.2:2.80,.22:3.01,.24:3.22,.26:3.

43,.3:3.87,.4:4.97,.5:6.07,.6:7.07,.7:8.07,.8:9.07,.9:10.07,1:11.07,1.1:12.07,1.2

:13.07,1.3:14.07,1.4:15.07,1.5:16.07,1.6:17.07,1.7:18.07,1.8:19.07,1.9:20.07,2:21

.07,40:199';

}

 

 

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_AIRMAILSIGNED_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_AIRMAILSIGNED_COST_" . $i ."', '" . $shipping_table . "', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weights less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_AIRMAILSIGNED_HANDLING_" . $i ."', '3.50', 'If you want to add extra costs to customers for jiffy bags etc, the cost can be entered below (eg enter 1.50 for a value of £1.50)', '6', '0', now())");

// tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_AIRMAIL_TAX_CLASS" . $i ."', '0', 'TEST TEST for TAX the cost can be entered below (eg enter 1.50 for a value of £1.50)', '6', '0', now())"); STILL MY ATTEMPT TO INCUDE VAT ON POSTAGE

}

}

// elari - Added to select default country if not in listing

 

function remove() {

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

}

 

function keys() {

$keys = array('MODULE_SHIPPING_AIRMAILSIGNED_STATUS', 'MODULE_SHIPPING_AIRMAILSIGNED_TAX_CLASS', 'MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER');

 

for ($i=1; $i<=$this->num_zones; $i++) {

$keys[] = 'MODULE_SHIPPING_AIRMAILSIGNED_COUNTRIES_' . $i;

$keys[] = 'MODULE_SHIPPING_AIRMAILSIGNED_COST_' . $i;

$keys[] = 'MODULE_SHIPPING_AIRMAILSIGNED_HANDLING_' . $i;

// $keys[] = 'MODULE_SHIPPING_AIRMAIL_TAX_CLASS' . $i; STILL MY ATTEMPT TO INCUDE VAT ON POSTAGE

}

 

return $keys;

}

}

?>

Share this post


Link to post
Share on other sites

Context means just relevant lines, not the whole thing :P

 

The problem is a missing closing brace '}' like so:

if ($shipping_weight > 2) {
$this->enabled = false;
}

Share this post


Link to post
Share on other sites

Ya sorry for the whole thing but there could be some thing else in the code that's wrong as i don't know PHP so didn't want to miss another problem.

I'm not sure what you mean by i'm missing closing brace, the code you gave is the same as i have already.

Share this post


Link to post
Share on other sites

Thanks natrium42 I get what you mean i was missing an extra } under the if statement

I now don't get the t_function error but still it shows the shipping when over 2KG or over £46 like its ignoring the if statements lol

 

This is the code i have now (small part)

 

$this->icon = DIR_WS_ICONS . 'shipping_airmail.gif'; // upload icon to catalog/images/icon directory

$this->tax_class = MODULE_SHIPPING_AIRMAILSIGNED_TAX_CLASS;

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

if ($order->delivery['country']['iso_code_2'] == 'GB') {

$this->enabled = false;

 

if ($total_weight > 2) {

$this->enabled = false;

}

 

if ($order->info['total'] > 46) {

$this->enabled = false;

}

 

}

// CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED

$this->num_zones = 2;

}

Share this post


Link to post
Share on other sites

That's because your code is plain wrong.

 

1. $shipping_weight is not fetched anywhere in your constructor, so the variable is empty -- something a simple echo statement would have verified.

2. Setting $this->enabled to false in quote() has no effect, since the shipping module system only checks that after the constructor. I think you could use "return null;" or "return array();" instead.

Share this post


Link to post
Share on other sites
That's because your code is plain wrong.

 

1. $shipping_weight is not fetched anywhere in your constructor, so the variable is empty -- something a simple echo statement would have verified.

2. Setting $this->enabled to false in quote() has no effect, since the shipping module system only checks that after the constructor. I think you could use "return null;" or "return array();" instead.

 

Thanks for your reply and time but i don't know a thing about PHP any chance you could write this small part of code for me to try.

Thanks for your time in advance.

 

Jonny

Share this post


Link to post
Share on other sites

Hey burt your solution is for james but i tried to implement it also as its also covering the same problem but in a slightly different way.

 

When i try i get

"Fatal error: Call to a member function show_weight() on a non-object in.... (on line 133)"

Edited by Dr_killer_UK

Share this post


Link to post
Share on other sites
Hey burt your solution is for james but i tried to implement it also as its also covering the same problem but in a slightly different way.

 

When i try i get

"Fatal error: Call to a member function show_weight() on a non-object in.... (on line 133)"

That means $cart is not available. Did you put "global $cart;" at the top of the function where you are doing this?

Share this post


Link to post
Share on other sites

The bit with the changes was as below.

 

class airmailsigned {

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

 

// class constructor

function airmailsigned() {

global $order, global $cart;

$this->code = 'airmailsigned';

$this->title = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_TITLE;

$this->description = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER;

$this->icon = DIR_WS_ICONS . 'shipping_airmail.gif'; // upload icon to catalog/images/icon directory

$this->tax_class = MODULE_SHIPPING_AIRMAILSIGNED_TAX_CLASS;

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

if ($order->delivery['country']['iso_code_2'] == 'GB') {

$this->enabled = false;

 

}

// CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED

$this->num_zones = 2;

if ($cart->show_weight() > 2) $this->enabled = false;

}

 

// class methods

Share this post


Link to post
Share on other sites

if($this->enabled )

{

if ($cart->show_weight() > 7) $this->enabled = true;

else

 

$this->enabled = flase;

 

}

 

 

Satish


Ask/Skype for Free osCommerce value addon/SEO suggestion tips for your site.

 

Check My About US For who am I and what My company does.

Share this post


Link to post
Share on other sites

Same error

 

Fatal error: Call to a member function show_weight() on a non-object in .... (on line 133)

 

Here is code as of now (i have marked what line 133 is ins the code to help)

 

class airmailsigned {

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

 

// class constructor

function airmailsigned() {

global $order, $cart;

$this->code = 'airmailsigned';

$this->title = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_TITLE;

$this->description = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER;

$this->icon = DIR_WS_ICONS . 'shipping_airmail.gif'; // upload icon to catalog/images/icon directory

$this->tax_class = MODULE_SHIPPING_AIRMAILSIGNED_TAX_CLASS;

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

if ($order->delivery['country']['iso_code_2'] == 'GB') {

$this->enabled = false;

 

}

// CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED

$this->num_zones = 2;

(this is line 133) if ($cart->show_weight() > 2) $this->enabled = false;

}

Share this post


Link to post
Share on other sites
if($this->enabled )

{

if ($cart->show_weight() > 7) $this->enabled = true;

else

 

$this->enabled = flase;

 

}

 

 

Satish

 

 

Thanks for the suggestion but it didn't stop showing over 2Kg The code i used was

 

if($this->enabled )

{

if ($cart->show_weight() < 2) $this->enabled = true;

else

 

$this->enabled = false;

 

}

Share this post


Link to post
Share on other sites

I have applied & tested the modification I talked above for you, since you do not seem to be able to. Here is the whole listing:

<?php
class airmailsigned {
 var $code, $title, $description, $enabled, $num_zones;

 // class constructor
 function airmailsigned() {
global $order, $shipping_weight;
$this->code = 'airmailsigned';
$this->title = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_TITLE;
$this->description = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER;
$this->icon = DIR_WS_ICONS . 'shipping_airmail.gif'; // upload icon to catalog/images/icon directory
$this->tax_class = MODULE_SHIPPING_AIRMAILSIGNED_TAX_CLASS;
$this->enabled = ((MODULE_SHIPPING_AIRMAILSIGNED_STATUS == 'True') ? true : false);

// CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
$this->num_zones = 2;
 }

 // class methods
 function quote($method = '') {
global $order, $shipping_weight, $shipping_num_boxes;

$dest_country = $order->delivery['country']['iso_code_2'];
$dest_zone = 0;
$error = false;
for ($i=1; $i<=$this->num_zones; $i++) {
  $countries_table = constant('MODULE_SHIPPING_AIRMAILSIGNED_COUNTRIES_' . $i);
  $country_zones = split("[,]", $countries_table);
  if (in_array($dest_country, $country_zones)) {
	$dest_zone = $i;
	break;
  }
}

// BOF: Mod
  if ($dest_country == 'GB') {
	return null;
  }

  if ($shipping_weight > 2) {
	return null;
  }
// EOF: Mod


// elari - Added to select default country if not in listing
if ($dest_zone == 0) {
  $dest_zone = $this->num_zones; // the zone is the lastest zone avalaible
}
// elari - Added to select default country if not in listing
if ($dest_zone == 0) {
  $error = true; // this can no more achieve since by default the value is set to the max number of zones
} else {
  $shipping = -1;
  $zones_cost = constant('MODULE_SHIPPING_AIRMAILSIGNED_COST_' . $dest_zone);

  $zones_table = split("[:,]" , $zones_cost);
  $size = sizeof($zones_table);
  for ($i=0; $i<$size; $i+=2) {
	if ($shipping_weight <= $zones_table[$i]) {
	  $shipping = $zones_table[$i+1];
	  if(tep_not_null($method) )
		// Text shown on Checkout_Confirmation
		$shipping_method = ''; // Leaving this entry blank causes only the shipping title to show i.e Royal Mail 1st Class Rec
	  else
		// Text shown on Checkout_shipping - Delivery Weight : 0.7 Kg's (Ships normally within 1 to 3 days)
		$shipping_method = MODULE_SHIPPING_AIRMAILSIGNED_TEXT_WAY . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_AIRMAILSIGNED_TEXT_UNITS . ' ' . MODULE_SHIPPING_AIRMAILSIGNED_DELIVERY_TIMES;
	  if ($shipping_num_boxes > 1) {
		$shipping_method .= $shipping_num_boxes . 'x ';
	  }
	break;
	}
  }

  if ($shipping == -1) {
	$shipping_cost = 0;
	$shipping_method = MODULE_SHIPPING_AIRMAILSIGNED_UNDEFINED_RATE;
  } else {
	$shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_AIRMAILSIGNED_HANDLING_' . $dest_zone);
  }
}
// I want to add VAT to European purchases
// If I add 1.175* at the start of line 183, then it works and adds 17.5%, but to ALL Zones
// How do I make it only apply to Zone 1 below - viz. ($i == 2)
// The following doesn't work either, but just leaving line 190 works as before - to ALL zones
// if ($i == 2) {
// $shipping_cost = $shipping_cost*1.175;
// }

$this->quotes = array('id' => $this->code,
					  'module' => MODULE_SHIPPING_AIRMAILSIGNED_TEXT_TITLE,
					  'methods' => array(array('id' => $this->code,
					  'title' => $shipping_method,
					  'cost' => $shipping_cost)));

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);

if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_AIRMAILSIGNED_INVALID_ZONE;

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_AIRMAILSIGNED_STATUS'");
  $this->_check = tep_db_num_rows($check_query);
}
return $this->_check;
 }

 // elari - Added to select default country if not in listing
 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 Zones Method', 'MODULE_SHIPPING_AIRMAILSIGNED_STATUS', 'True', 'Do you want to offer zone 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, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_AIRMAILSIGNED_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, date_added) values ('Sort Order', 'MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER', '10', 'Sort order of display.', '6', '0', now())");
for ($i = 1; $i <= $this->num_zones; $i++) {
  $default_countries = '';
  if ($i == 1) {
	$default_countries = 'AL,AD,AM,AT,AZ,BY,BE,BA,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GI,GR,GL,HU,IS,IE,I
	T,KZ,KG,LV,LI,LT,LU,MK,MT,MD,MC,NL,NO,PL,PT,RO,RU,SM,SK,SI,ES,SE,CH,TJ,TR,T
M,UA,U
	Z,VA';
	//Airmail Rates for Europe at April 2007: Small packets to 2KG and printed Papers to 10KG (2 packets)
	$shipping_table = '.1:1.24,.12:1.36,.14:1.50,.16:1.63,.18:1.77,.2:1.90,.22:2.03,.24:2.15,.26:2.
	28,.28:2.39,.3:2.51,.4:3.06,.5:3.61,.6:4.11,.7:4.61,.8:5.11,.9:5.61,1:6.11,1.1:6.
	61,1.2:7.11,1.3:7.61,1.4:8.11,1.5:8.61,1.6:9.11,1.7:9.61,1.8:10.11,1.9:10.61,2:11
	.11,40:199';
  }
  if ($i == 2) {
	$default_countries = 'All Others'; // this must be the lastest zone
	// Airmail Rates for Rest of World at April 2007: Small packets to 2KG and printed Papers to 10KG (2 packets)
	$shipping_table = '.1:1.64,.12:1.87,.14:2.10,.16:2.33,.18:2.56,.2:2.80,.22:3.01,.24:3.22,.26:3.
	43,.3:3.87,.4:4.97,.5:6.07,.6:7.07,.7:8.07,.8:9.07,.9:10.07,1:11.07,1.1:12.07,1.2
	:13.07,1.3:14.07,1.4:15.07,1.5:16.07,1.6:17.07,1.7:18.07,1.8:19.07,1.9:20.07,2:21
	.07,40:199';
  }


  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_AIRMAILSIGNED_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_AIRMAILSIGNED_COST_" . $i ."', '" . $shipping_table . "', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weights less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_AIRMAILSIGNED_HANDLING_" . $i ."', '3.50', 'If you want to add extra costs to customers for jiffy bags etc, the cost can be entered below (eg enter 1.50 for a value of £1.50)', '6', '0', now())");
  // tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_AIRMAIL_TAX_CLASS" . $i ."', '0', 'TEST TEST for TAX the cost can be entered below (eg enter 1.50 for a value of £1.50)', '6', '0', now())"); STILL MY ATTEMPT TO INCUDE VAT ON POSTAGE
}
 }
 // elari - Added to select default country if not in listing

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

 function keys() {
$keys = array('MODULE_SHIPPING_AIRMAILSIGNED_STATUS', 'MODULE_SHIPPING_AIRMAILSIGNED_TAX_CLASS', 'MODULE_SHIPPING_AIRMAILSIGNED_SORT_ORDER');

for ($i=1; $i<=$this->num_zones; $i++) {
  $keys[] = 'MODULE_SHIPPING_AIRMAILSIGNED_COUNTRIES_' . $i;
  $keys[] = 'MODULE_SHIPPING_AIRMAILSIGNED_COST_' . $i;
  $keys[] = 'MODULE_SHIPPING_AIRMAILSIGNED_HANDLING_' . $i;
  // $keys[] = 'MODULE_SHIPPING_AIRMAIL_TAX_CLASS' . $i; STILL MY ATTEMPT TO INCUDE VAT ON POSTAGE
}

return $keys;
 }
}
?>

Edited by natrium42

Share this post


Link to post
Share on other sites

YOUR A STAR! B) have to ware shades for the brightness.

 

Anyways your code worked a charm. I added extra code that worked thanks to your help (going by how you wrote the other parts) so now i have a limit of weight and price using the following:

 

// BOF: Mod

if ($dest_country == 'GB') {

return null;

}

 

if ($shipping_weight > 2) {

return null;

}

 

if ($order->info['total'] > 46) {

return null;

}

// EOF: Mod

 

I should be able to figure all shipping from there for multiple zones with out any problems.

 

Thanks again

Jonny

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×