Jump to content

Shipping by Weight - 3rd Option Help


Guest benlogan

Recommended Posts

Guest benlogan

Hi, I have my shipping almost set-up, I just need some help with if and else statements. Ive programmed other languges, just not php. This is my calc.php for by_weight shipping:

<?php

/*

+--------------------------------------------------------------------------

|   CubeCart v3.0.2

|   ========================================

|   by Alistair Brookbanks

|	CubeCart is a Trade Mark of Devellion Limited

|   (c) 2005 Devellion Limited

|   Devellion Limited,

|   Westfield Lodge,

|   Westland Green,

|   Little Hadham,

|   Nr Ware, HERTS.

|   SG11 2AL

|   UNITED KINGDOM

|   http://www.devellion.com

|	UK Private Limited Company No. 5323904

|   ========================================

|   Web: http://www.cubecart.com

|   Date: Friday, 12 August 2005

|   Email: info (at) cubecart (dot) com

|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 

|   Licence Info: http://www.cubecart.com/site/faq/license.php

+--------------------------------------------------------------------------

|	calc.php

|   ========================================

|	Calculates shipping by weight (Lbs or Kgs)	

+--------------------------------------------------------------------------

*/

// per category shipping module

$module = fetchDbConfig("By_Weight");



if($module['status']==1){



// get the delivery ISO

$countryISO = countryIso($basket['delInf']['country']);



// build array of ISO Codes

$zones['1'] = explode(",",$module['zone1Countries']);

$zones['2'] = explode(",",$module['zone2Countries']);

$zones['3'] = explode(",",$module['zone3Countries']);

$zones['4'] = explode(",",$module['zone4Countries']);



// find the country

foreach ($zones as $key => $value){



	foreach($zones[$key] as $no => $iso){

	

  if($iso == $countryISO){

  

 	 $shipZone = $key;

  

  }

	

	}



}



if(!isset($shipZone)){

	header("Location: cart.php?act=noShip");

	exit;

}



// work out cost

$shipBands = explode(",",$module['zone'.$shipZone.'RatesClass1']);

$noBands = count($shipBands);



if($noBands>1){



	for($n=0; $n<count($shipBands);$n++){

	

  $wheightCost = explode(":",$shipBands[$n]);

  

  if($totalWeight<=$wheightCost[0]){

 	 

 	 $sumClass1 = $wheightCost[1]+$module['zone'.$shipZone.'Handling'];

 	 break;

 	 

  } elseif($totalWeight>$wheightCost[0] && $n+1==$noBands){

  

 	 header("Location: cart.php?act=overWeight");

 	 exit;

  

  }

	

	}

	

}



unset($shipBands, $noBands);



$shipBands = explode(",",$module['zone'.$shipZone.'RatesClass2']);

$noBands = count($shipBands);



if($noBands>1){



	for($n=0; $n<count($shipBands);$n++){

	

  $wheightCost = explode(":",$shipBands[$n]);

  

  if($totalWeight<=$wheightCost[0]){

 	 

 	 $sumClass2 = $wheightCost[1]+$module['zone'.$shipZone.'Handling'];

 	 break;

 	 

  } elseif($totalWeight>$wheightCost[0] && $n+1==$noBands){

  

 	 header("Location: cart.php?act=overWeight");

 	 exit;

  

  }

	

	}

	

}



unset($shipBands, $noBands);



if($sum == 0){

	$sum = 0.00;

}



$taxVal = taxRate($module['tax']);



if($sumClass1>0){



	if($taxVal>0){

	

  $val = ($taxVal / 100) * $sumClass1;

  $sumClass1 = $sumClass1 + $val;

	}



	$shippingPrice .= "<option value='".$i."C1|".$sumClass1."'";

	

	if($i."C1" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (1st Class)","shipMethod");

	}

	

	$sum = $sumClass1;

	

	$shippingPrice .= ">".priceFormat($sumClass1)." AusPost ExpressPost</option>\r\n";

	

  $shippingPrice .= "<option value='".$i."C2|".$sumClass1."'";

	

	if($i."C2" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (1st Class)","shipMethod");

	}

	

	$sum = $sumClass1;

	

	$shippingPrice .= ">".priceFormat($sumClass1)." AusPost ExpressPost Platinum</option>\r\n";



}



if($sumClass2>0){



	if($taxVal>0){

	

  $val = ($taxVal / 100) * $sumClass2;

  $sumClass2 = $sumClass2 + $val;

	}



	$shippingPrice .= "<option value='".$i."C3|".$sumClass2."'";

	

	if($i."C3" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (2nd Class)","shipMethod");

	}

	

	$shippingPrice .= ">".priceFormat($sumClass2)." AusPost International Air</option>\r\n";

	

  $shippingPrice .= "<option value='".$i."C4|".$sumClass2."'";

	

	if($i."C4" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (2nd Class)","shipMethod");

	}

	

	$shippingPrice .= ">".priceFormat($sumClass2)." AusPost International EconomyAir</option>\r\n";

	

	

	

}

unset($module, $taxVal);

}

?>

Now I want to do this,

if countrycode is AU (Australia) -> detect what customers country code is

add AusPost Express -> if au, add/display these two options

add AusPost Express Platinum

else -> if not au, add the two options below.

add Internation Air

add International EconAir

end if

i dotn know php code, so i assumed it was like that.

Link to comment
Share on other sites

Guest benlogan

ok, dont worry about it. I fixed my own problem.

i did this to do it.

if($countryISO == "AU"){

adds the auspost express and pltinum

}

else{

adds international options

}

here is the full code.

<?php

/*

+--------------------------------------------------------------------------

|   CubeCart v3.0.2

|   ========================================

|   by Alistair Brookbanks

|	CubeCart is a Trade Mark of Devellion Limited

|   (c) 2005 Devellion Limited

|   Devellion Limited,

|   Westfield Lodge,

|   Westland Green,

|   Little Hadham,

|   Nr Ware, HERTS.

|   SG11 2AL

|   UNITED KINGDOM

|   http://www.devellion.com

|	UK Private Limited Company No. 5323904

|   ========================================

|   Web: http://www.cubecart.com

|   Date: Friday, 12 August 2005

|   Email: info (at) cubecart (dot) com

|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 

|   Licence Info: http://www.cubecart.com/site/faq/license.php

+--------------------------------------------------------------------------

|	calc.php

|   ========================================

|	Calculates shipping by weight (Lbs or Kgs)	

+--------------------------------------------------------------------------

*/

// per category shipping module

$module = fetchDbConfig("By_Weight");



if($module['status']==1){



// get the delivery ISO

$countryISO = countryIso($basket['delInf']['country']);



// build array of ISO Codes

$zones['1'] = explode(",",$module['zone1Countries']);

$zones['2'] = explode(",",$module['zone2Countries']);

$zones['3'] = explode(",",$module['zone3Countries']);

$zones['4'] = explode(",",$module['zone4Countries']);



// find the country

foreach ($zones as $key => $value){



	foreach($zones[$key] as $no => $iso){

	

  if($iso == $countryISO){

  

 	 $shipZone = $key;

  

  }

	

	}



}



if(!isset($shipZone)){

	header("Location: cart.php?act=noShip");

	exit;

}



// work out cost

$shipBands = explode(",",$module['zone'.$shipZone.'RatesClass1']);

$noBands = count($shipBands);



if($noBands>1){



	for($n=0; $n<count($shipBands);$n++){

	

  $wheightCost = explode(":",$shipBands[$n]);

  

  if($totalWeight<=$wheightCost[0]){

 	 

 	 $sumClass1 = $wheightCost[1]+$module['zone'.$shipZone.'Handling'];

 	 break;

 	 

  } elseif($totalWeight>$wheightCost[0] && $n+1==$noBands){

  

 	 header("Location: cart.php?act=overWeight");

 	 exit;

  

  }

	

	}

	

}



unset($shipBands, $noBands);



$shipBands = explode(",",$module['zone'.$shipZone.'RatesClass2']);

$noBands = count($shipBands);



if($noBands>1){



	for($n=0; $n<count($shipBands);$n++){

	

  $wheightCost = explode(":",$shipBands[$n]);

  

  if($totalWeight<=$wheightCost[0]){

 	 

 	 $sumClass2 = $wheightCost[1]+$module['zone'.$shipZone.'Handling'];

 	 break;

 	 

  } elseif($totalWeight>$wheightCost[0] && $n+1==$noBands){

  

 	 header("Location: cart.php?act=overWeight");

 	 exit;

  

  }

	

	}

	

}



unset($shipBands, $noBands);



if($sum == 0){

	$sum = 0.00;

}



$taxVal = taxRate($module['tax']);

if($countryISO == "AU"){

if($sumClass1>0){



	if($taxVal>0){

	

  $val = ($taxVal / 100) * $sumClass1;

  $sumClass1 = $sumClass1 + $val;

	}



	$shippingPrice .= "<option value='".$i."C1|".$sumClass1."'";

	

	if($i."C1" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (1st Class)","shipMethod");

	}

	

	$sum = $sumClass1;

	

	$shippingPrice .= ">".priceFormat($sumClass1)." AusPost ExpressPost</option>\r\n";

	

  $shippingPrice .= "<option value='".$i."C2|".$sumClass1."'";

	

	if($i."C2" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (1st Class)","shipMethod");

	}

	

	$sum = $sumClass1;

	

	$shippingPrice .= ">".priceFormat($sumClass1)." AusPost ExpressPost Platinum</option>\r\n";

}

}

else{

if($sumClass2>0){



	if($taxVal>0){

	

  $val = ($taxVal / 100) * $sumClass2;

  $sumClass2 = $sumClass2 + $val;

	}



	$shippingPrice .= "<option value='".$i."C3|".$sumClass2."'";

	

	if($i."C3" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (2nd Class)","shipMethod");

	}

	

	$shippingPrice .= ">".priceFormat($sumClass2)." AusPost International Air</option>\r\n";

	

  $shippingPrice .= "<option value='".$i."C4|".$sumClass2."'";

	

	if($i."C4" == $optNo){

  $shippingPrice .= "selected='selected'";

  $basket = $cart->setVar("By Weight (2nd Class)","shipMethod");

	}

	

	$shippingPrice .= ">".priceFormat($sumClass2)." AusPost International EconomyAir</option>\r\n";

	

	}

	

}

unset($module, $taxVal);

}

?>

Link to comment
Share on other sites

Good work, Ben. I'm not a programmer, I'm lost in php. If I were in your shoes, I'd love to have such a program. It seems to me that as the CC prog now stands, you'd have to specify each additional country you wish to service in zones 3-4 and set prices for them there. If I understand correctly, you can now set two service levels/shipping rates for AU, and two service levels/shipping rates for * everywhere else in the universe?

Cool :D

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
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...