Jump to content

Shipping problem


Guest jkrische

Recommended Posts

Guest jkrische

Here's the nut of shipping the problem, as I have encountered it:

The page in the cart which displays shipping -- stage 4 -- expects the user to do 1 of two things:

1. click the Update Cart button to get shipping to apply

2. use the pull-down of the available shipping prices to choose 1.

The shipping chosen only applies *if the selection changes*

(javascript onChange() event).

This is a logical impossibility if only 1 shipping method is allowed.

Such is the case for the client I'm using cubecart for; per-category in

this client's specific case, but that is irrelevant. The problem is

that shipping only applies when the selection changes;

this will be true for any cart that only offers 1 shipping cost.

Clicking the Continue button, like a normal person does, does NOT tell the cart to update and add shipping.

Therein lies the problem. So, 1 of 2 things has to happen:

1. Force the shipping to be added with the Continue button, or

2. Force the shipping to be added even if the selection does NOT change

(not tied to an onChange event).

I've tried digging into the code of the cart but without an API or other significant documentation, I'm kinda flying blind. I remember reading a post here in the forums somewhere that made the shipping apply when Stage 4 loads but I can't find it now. (help?)

I've also tried adding a "Please choose a shipping cost below" item, but it always appears below the pre-chosen "normal" ship cost; it also does not solve the possibility of what should happen if they simply don't choose... the selection didn't change, so shipping would not get applied, nevermind that the "Please Choose" entry would not have an actual value attached to it.

So, Mod gurus, Brooky... what's the fix?

Link to comment
Share on other sites

Guest benlogan

Hi, mate, here is my calc.php for by weight. It has two different methods for my country (AU) and two methods for all other countires. It also has the "Please select shipping method."

Here it is: calc.php

<?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']);

$SelectMethod = "Please select a shipping method.";           // **** See here, I added the variable to show the text. ****





// 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']);



//start "please select method"

	$shippingPrice .= "<option value='".$i."C0|".$SelectMethod."'";

	

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

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

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

}

	

	$shippingPrice .= ">".$SelectMethod."</option>\r\n";    // **** Here is the variable wer made up the top. Displays it at the top of the dropdown box ****



//end method

	





if($countryISO == "AU"){ // **** Checks if users country is Australia, if it is, it loads the two shipping options below. Replace AU with your country iso/code ****

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";        // **** Adds shipping method #1 ****

	

  $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";// **** Adds shipping method #2 ****

}

}

else{         // **** If the users country ISNT australia, it assumes it is an international order and loads these two shippinh methods ****

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"; // **** Adds international shipping method #1 ****

	

  $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"; // **** Adds international shipping method #2 ****

	

	}

	

}

unset($module, $taxVal);

}



?>




Also, here is my admin page to, so that is all managable.



Here it is: index.php of by_weight




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

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

|	index.php

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

|	Configure Shipping By Weight

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

*/

include("../../../../includes/ini.inc.php");

include("../../../../includes/global.inc.php");

require_once("../../../../classes/db.inc.php");

$db = new db();

include_once("../../../../includes/functions.inc.php");

$config = fetchDbConfig("config");



include_once("../../../../language/".$config['defaultLang']."/lang.inc.php");

$enableSSl = 1;

include_once("../../../../includes/sslSwitch.inc.php");

include("../../../includes/auth.inc.php");

include("../../../includes/header.inc.php");



if(permission("settings","read")==FALSE){

	header("Location: ".$GLOBALS['rootRel']."admin/401.php");

	exit;

}



if(isset($_POST['module'])){

	include("../../status.php");

	include("../../../includes/functions.inc.php");

	$module = fetchDbConfig($_GET['folder']);

	$msg = writeDbConf($_POST['module'], $_GET['folder'], $module);

	

}

$module = fetchDbConfig($_GET['folder']);

?>

<?php 

if(isset($msg)){ 

	echo $msg; 

} 

?>



<p class="copyText">This module is for shipping by Weight (Please make sure you have the correct weight unit selected in your settings)</p>

<form action="<?php echo $GLOBALS['rootRel'];?>admin/modules/<?php echo $_GET['module']; ?>/<?php echo $_GET['folder']; ?>/index.php?module=<?php echo $_GET['module']; ?>&amp;folder=<?php echo $_GET['folder']; ?>" method="post" enctype="multipart/form-data">

<table border="0" cellspacing="0" cellpadding="3" class="mainTable">

  <tr>

    <td colspan="2" class="tdTitle">Configuration Settings </td>

  </tr>

  <tr>

    <td align="left" class="tdText"><strong>Status:</strong></td>

    <td class="tdText">

	<select name="module[status]">

	<option value="1" <?php if($module['status']==1) echo "selected='selected'"; ?>>Enabled</option>

	<option value="0" <?php if($module['status']==0) echo "selected='selected'"; ?>>Disabled</option>

    </select></td>

  </tr>

  <tr>

    <td align="left" valign="top" class="tdOdd"><span class="copyText"><strong>Zone 1 Countries:</strong><br />

      (List comma separated ISO codes)</span></td>

    <td class="tdOdd"><textarea name="module[zone1Countries]" cols="40" rows="2" class="textbox"><?php echo $module['zone1Countries']; ?></textarea>

	</td>

  </tr>

  <tr>

    <td align="left" valign="top" class="tdOdd"><span class="tdText"><strong>National Handling Fee:</strong></span></td>

    <td class="tdOdd"><input type="text" name="module[zone1Handling]" value="<?php echo $module['zone1Handling']; ?>" class="textbox" size="5" /></td>

  </tr>

  <tr>

    <td align="left" valign="top" class="tdOdd"><span class="tdText"><strong>AusPost ExpressPost:</strong> <br />(Comma Separated)    </span></td>

    <td class="tdOdd"><input type="text" name="module[zone1RatesClass1]" value="<?php echo $module['zone1RatesClass1']; ?>" class="textbox" size="40" />	</td>

  </tr>

  <tr>

    <td align="left" valign="top" class="tdOdd"><span class="tdText"><strong>AusPost ExpressPost Platinum:</strong> <br />

      (Comma Separated) </span></td>

    <td class="tdOdd"><input type="text" name="module[zone1RatesClass2]" value="<?php echo $module['zone1RatesClass2']; ?>" class="textbox" size="40" /></td>

  </tr>

    <tr>

    <td align="left" valign="top" class="tdEven"><span class="tdText"><strong>International Countries:</strong></span></td>

    <td class="tdEven"><textarea name="module[zone2Countries]" cols="40" rows="2" class="textbox"><?php echo $module['zone2Countries']; ?></textarea>

	</td>

  </tr>

  <tr>

    <td align="left" valign="top" class="tdEven"><span class="tdText"><strong>International Handling Fee: </strong></span></td>

    <td class="tdEven"><input type="text" name="module[zone2Handling]" value="<?php echo $module['zone2Handling']; ?>" class="textbox" size="5" /></td>

  </tr>

  <tr>

    <td align="left" valign="top" class="tdEven"><span class="tdText"><strong>AusPost International AirMail:</strong> <br />

        (Comma Separated)    </span></td>

    <td class="tdEven"><input type="text" name="module[zone2RatesClass1]" value="<?php echo $module['zone2RatesClass1']; ?>" class="textbox" size="40" /></td>

  </tr>

  <tr>

    <td align="left" valign="top" class="tdEven"><span class="tdText"><strong>AusPost International EconomyAir:</strong> <br />

(Comma Separated)</span></td>

    <td class="tdEven"><input type="text" name="module[zone2RatesClass2]" value="<?php echo $module['zone2RatesClass2']; ?>" class="textbox" size="40" /></td>

  </tr>

  <tr>

    <td align="left" class="tdText"><strong>Tax Class: </strong></td>

    <td class="tdText"><?php

	$tax = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_taxes");

	?>

	<select name="module[tax]">

	<?php for($i=0; $i<count($tax); $i++){ ?>

	<option value="<?php echo $tax[$i]['id']; ?>" <?php if($module['tax'] == $tax[$i]['id']) echo "selected='selected'"; ?>>

	<?php echo $tax[$i]['taxName']; ?>

	</option>

	<?php } ?>

	</select></td>

  </tr>

  <tr>

    <td align="right" class="tdText">&nbsp;</td>

    <td class="tdText"><input type="submit" class="submit" value="Edit Config" /></td>

  </tr>

</table>

<p class="copyText">Shipping rates are worked out by weight/price.</p>

<p class="copyText">e.g. 1:1.29 (For a parcel of 1<?php echo $config['weightUnit']; ?> or under the shipping would be 1.29 <?php echo $config['defaultCurrency'];?>) </p>

</form>

<?php include("../../../includes/footer.inc.php"); ?>

Link to comment
Share on other sites

Guest jkrische

Thanks, Ben, for the considerate and useful reply.

If you don't mind, I do have a question or two for you regarding your solution, which by the way is one of the solutions I've looked at in your other forum posts.

First, your solution is presented for the "by weight" shipping method. Is the fundamental change you've made to calc.php equally applicable when "by category" is the chosen method?

Second, I haven't fully looked through your code yet but will be doing so shortly. Does your calc.php modification address the issue of using a "Please choose" menu item, but the user does not actually chose, thus not triggering the onChange() event? If I recall correctly (I'm not at my normal development machine at the moment), the placement of the onChange event is not actually in calc.php but in another file.

Thanks again, Ben.

I should note for this thread that the appearance of this issue is somewhat inconsistent. The only pattern I've been able to identify thus far is that the shipping does not get properly applied under the "by category" rules when 2 things are true:

  • The cart only offers 1 shipping cost, and
  • the customer's country is listed in the "international" category of the "by category" structure.

This may prove useful in diagnosing the problem and developing the proper solution.

Link to comment
Share on other sites

Guest benlogan

Hey,

I am not sure about by category, but I will have a look. The only problem with this code is,

The user can leave it on "Please select shipping method." and get free shipping. I have been working on a way to fix it. But to no avail.

Also, if a user selects their shipping, then adds or removes a product, it will update, but NOT to the correct prices.

skins\whateverskinyouuse\styleTemplates\content\cart.tpl

Now my solution was, to do this:

at the onclick, (its down the very bottom)

compare the cart total with the sub-total. If they are the sme, then shippinh hasnt been selected. display a msg box saying so.

if they are different, shippinh has been selected nad let them through.

But that method still doesnt solve, the problem of adding and removing items.

Link to comment
Share on other sites

Guest benlogan

Ok, and your questions. Well, as for the "Please choose..."

It will be displayed first, the user then selects a method, the price is updated. if they click back on "Please choose..." it will take the shipping off. I am just editing it a bit now, to see if i can fix that.

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