Verification function of Postcode needed - Auspost

  • Posts: 7
  • Thank you received: 0
12 years 6 months ago #48957

When a customer enters the wrong postcode then this leads to a $0 postage fee.
This happens easily from an Apple computer with Safari with the Autofill function - the postcode is not properly inserted - instead the address data (street/number) ends up in the postcode field as well. There need to be a function to validate the postcode (in Australia numeric/4digits) and produce an error message before processing the final check-out.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
12 years 6 months ago #49035

Hi,

Change the code:

if(empty($order->shipping_address->address_post_code)){
						$zoneClass=hikashop_get('class.zone');
							$zones = $zoneClass->getOrderZones($order);
							$db =& JFactory::getDBO();
						$db->setQuery('SELECT zone_namekey FROM '.hikashop_table('zone').' WHERE zone_code_3='.$db->Quote('AUS'));
						$australia_zone = $db->loadResult();
						if(in_array($australia_zone,$zones)){
							$messages['post_code_missing'] = 'The Australia Post shipping plugin requires the user to enter a postal code when goods are shipped within Australia. Please go to "Display->Custom fields" and set the post code field to required.';
							continue;
						}
					}
to:
$check = false;
					if(empty($order->shipping_address->address_post_code)){
						$check = true;
						$message = 'The Australia Post shipping plugin requires the user to enter a postal code when goods are shipped within Australia. Please go to "Display->Custom fields" and set the post code field to required.';
					}elseif(!preg_match('#[0-9]{4}#',$order->shipping_address->address_post_code)){
						$check = true;
						$message = 'The post code entered is not valid';
					}
					if($check){
						$zoneClass=hikashop_get('class.zone');
							$zones = $zoneClass->getOrderZones($order);
							$db =& JFactory::getDBO();
						$db->setQuery('SELECT zone_namekey FROM '.hikashop_table('zone').' WHERE zone_code_3='.$db->Quote('AUS'));
						$australia_zone = $db->loadResult();
						if(in_array($australia_zone,$zones)){
							$messages['post_code_missing'] = $message;
							continue;
						}
					}
in the file plugins/hikashopshipping/aupost.php and that should do the job.

Please Log in or Create an account to join the conversation.

  • Posts: 28
  • Thank you received: 2
12 years 6 months ago #49038

Would this be easy to change for use in the USPS plug in? If not could I get you to help me with it?

Please Log in or Create an account to join the conversation.

  • Posts: 7
  • Thank you received: 0
12 years 6 months ago #49057

Thanks for the quick fix - I have tested it and it works good. Are you publishing an official version of the Auspost plugin soon with all the changes? Or are they already included in the official packages? We are considering getting the business version soon and want to make sure the version will be up to date.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
12 years 6 months ago #49132

The same code is used int he USPS plugin:

if(empty($order->shipping_address->address_post_code)){
						$zoneClass=hikashop_get('class.zone');
							$zones = $zoneClass->getOrderZones($order);
							$db =& JFactory::getDBO();
						$db->setQuery('SELECT zone_namekey FROM '.hikashop_table('zone').' WHERE zone_code_3='.$db->Quote('USA'));
						$usa_zone = $db->loadResult();
						if(in_array($us_zone,$zones)){
							$messages['post_code_missing'] = 'The USPS shipping plugin requires the user to enter a postal code when goods are shipped within the United States. Please go to "Display->Custom fields" and set the post code field to required.';
							continue;
						}
					}

So you can do the same modification:
$check = false;
					if(empty($order->shipping_address->address_post_code)){
						$check = true;
						$message = 'The USPS shipping plugin requires the user to enter a postal code when goods are shipped within the United States. Please go to "Display->Custom fields" and set the post code field to required.';
					}elseif(!preg_match('#^[0-9]{5}(-?[0-9]{4})?$#',$order->shipping_address->address_post_code)){
						$check = true;
						$message = 'The post code entered is not valid';
					}
					if($check){
						$zoneClass=hikashop_get('class.zone');
							$zones = $zoneClass->getOrderZones($order);
							$db =& JFactory::getDBO();
						$db->setQuery('SELECT zone_namekey FROM '.hikashop_table('zone').' WHERE zone_code_3='.$db->Quote('USA'));
						$usa_zone = $db->loadResult();
						if(in_array($usa_zone,$zones)){
							$messages['post_code_missing'] = $message;
							continue;
						}
					}

The aupost being included in HikaShop, the modification will be in next version of HikaShop.
It won't be added until then, but you can just reapply it after upgrading if you want to upgrade before the next version.

The following user(s) said Thank You: Mike2001

Please Log in or Create an account to join the conversation.

  • Posts: 28
  • Thank you received: 2
12 years 6 months ago #49620

Thanks again Nicolas...

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum