Shopping Cart Zip/Postal Code

General ShopSite user discussion

Shopping Cart Zip/Postal Code

Postby mike_peak » Fri Oct 05, 2007 4:27 am

I have just implemented a custom shipping script that will choose a shipping cost depending on order value/country chosen.

The post code/zip code entry box always appears and I understand there is no way of removing this. We are using UK post codes mostly which have a space in them, and when I enter a post code with a space it appears to break the shipping script (not all variables are sent to the shipping script like sXprice).

This could be an error in my script (I have taken the script off this forum) or is there a reason for not passing all variables when the post code has a space in it? Spaces at the beginning or end of the post code are fine, its just when there is a space inside the post code.

The script is as follows:

-----------------------------------------------------

#!/usr/local/bin/php -q
<?PHP

// Note: $_POST variable not available since this script is called as a
// CGI script, so we have to read in our params from stdin, with length
// determined by the CONTENT_LENGTH environment variable.

// Read in POST parameters sent by ShopSite
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%{$SERVER['CONTENT_LENGTH']}s",$query_string);

// And now we split the params into the $params array.
parse_str($query_string,$params);


if ( $params['cust_country'] && $params['item_total'] )

-----------------------------------------------------

The final if statement is evaluated as false when there is a space in the post code.

I have tried giving the zip code a value by default using javascript(then my plan was to try and hide the zip code entry box as we dont need it).

I tried:

document.order.zip_code.value = "12345";

But this seems to be ignored - does anyone know if there is a way to hide the zip entry using javascript and giving it a default value (or if my script is just in fact wrong)?
mike_peak
 
Posts: 10
Joined: Tue Feb 13, 2007 3:44 am

Postby mike_peak » Mon Oct 08, 2007 4:28 am

I have sort of fixed this but I am not sure if the fix could cause other problems.

I added the following lines to the start of the checkIt method using the "Javascript added at start of built-in CheckIt function" field:

document.order.zip_code.value = '12345';
document.order.zip_code.defaultValue = '12345';
zip_recalc = 0;

This gets around some checks on the zip code so the customer can checkout without touching the zip code box.

I also overloaded the zip_changed() function by adding:

function zip_changed() { return false; }

This is so the checkout does not resubmit when the zip code value is changed manually. This is added after the original function and I added it into the template directly.

I then added a function called hideZip which is called via <body onload="hideZip()"> which hides the post code entry box using:

var zip = document.getElementsByName("zip_code");
zip[0].style.display = "none";

Finally I got rid of the text associated with the zip code so it appears as if there is no zip code entry at all.

This seems to work but does anyone know if there are possible problems I might have with this?
mike_peak
 
Posts: 10
Joined: Tue Feb 13, 2007 3:44 am

Postby mike_peak » Mon Oct 08, 2007 6:55 am

Okay that was way over complicated and messed the checkout up as the checkout has postcode checks in also which I didn't think about.

I have instead opted to go for javascript in the checkIt function on the shopping cart page:

document.order.zip_code.value = document.order.zip_code.value.replace(' ', '');
document.order.zip_code.defaultValue = document.order.zip_code.value;
zip_recalc = 0;

This gets rid of any spaces a customer might put into the post code and also skips the recalculation if the postcode is altered.

This solves my problem, I think.
mike_peak
 
Posts: 10
Joined: Tue Feb 13, 2007 3:44 am


Return to User Forum

Who is online

Users browsing this forum: No registered users and 104 guests

cron