Post by nbrofree » Tue Apr 06, 2021 7:47 pm

Some customers add whitespaces on checkout postcode field. I try to remove those spaces and also do a check for letters. (OC2.3.0.2 & journal2)
Example: if postcode is '12 3 t45 ' make it '12345'.

Simple mod I tried:

Code: Select all

<file path="catalog/model/checkout/order.php">
		<operation error="skip">
		<search><![CDATA[($data['payment_postcode'])]]></search> //also same operation for for shipping_postcode
		<add position="replace">
		<![CDATA[(preg_replace('/\D/', '', str_replace(' ','',$data['payment_postcode'] )))]]> //also tried suimply: (str_replace(' ','',$data['payment_postcode'] ))
		</add>
	</operation>
</file>
However it is not working and when I place a testorder msyself, I still see '12 3 t45 '. When creating the mod I saw some errors but I finished and I know the mod is loaded correctly (cache cleared and all...).

Any ideas dear Opencarters? Am I missing something?

Newbie

Posts

Joined
Thu Mar 04, 2021 12:23 am

Post by straightlight » Tue Apr 06, 2021 8:53 pm

While Journal is not supported on the forum, the preg_replace line is where it's wrong. See this e.g instead with str_replace: https://thisinterestsme.com/php-remove-whitespaces/ . In addition, you are only removing empty spaces on the payment_postcode. Also ensure the shipping_postcode also removes the empty spaces.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nbrofree » Tue Apr 06, 2021 9:20 pm

straightlight wrote:
Tue Apr 06, 2021 8:53 pm
While Journal is not supported on the forum, the preg_replace line is where it's wrong. See this e.g instead with str_replace: https://thisinterestsme.com/php-remove-whitespaces/ . In addition, you are only removing empty spaces on the payment_postcode. Also ensure the shipping_postcode also removes the empty spaces.
While I do apperciate your answer, I mention in the comments that I tried simply
"(str_replace(' ','',$data['payment_postcode'] ))"
just in case preg_replace was the wrong way to go.
Also in the comments, I mention that I had the same operation for "shipping_postcode". Chances are that I was not clear enough so, I appologize. :)

Newbie

Posts

Joined
Thu Mar 04, 2021 12:23 am

Post by straightlight » Tue Apr 06, 2021 10:12 pm

nbrofree wrote:
Tue Apr 06, 2021 9:20 pm
straightlight wrote:
Tue Apr 06, 2021 8:53 pm
While Journal is not supported on the forum, the preg_replace line is where it's wrong. See this e.g instead with str_replace: https://thisinterestsme.com/php-remove-whitespaces/ . In addition, you are only removing empty spaces on the payment_postcode. Also ensure the shipping_postcode also removes the empty spaces.
While I do apperciate your answer, I mention in the comments that I tried simply
"(str_replace(' ','',$data['payment_postcode'] ))"
just in case preg_replace was the wrong way to go.
Also in the comments, I mention that I had the same operation for "shipping_postcode". Chances are that I was not clear enough so, I appologize. :)
However, what you also mentioned is that the solution you first provided does not provide the result you expected and which is why you are requesting for custom codes assistance on the forum.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nbrofree » Wed Apr 07, 2021 1:03 am

straightlight wrote:
Tue Apr 06, 2021 10:12 pm
However, what you also mentioned is that the solution you first provided does not provide the result you expected and which is why you are requesting for custom codes assistance on the forum.
Yes sir, I agree that I am the one needing help here, never claimed otherwise and did not claim that I had a solution. Again, I totally respect and appreciate anyone who tries to help someone else and I do value their time. Having said that, I do not know why we are having this conversation. I am trying my best to be clear with my problem to get help faster from anyone kind enough to provide his valuable time. In the end, I think it is highly likely that someone will find the solution to 'cleaning' the postcode, useful.


Anyway... As I said, I tried to clean up the postcode variable (both payment and shipping) but it feels weird not working when I can see it being cached. Moreover, I tried to find if Journal somehow overrides anything but I am quite sure this is not the case. Still, I will keep in mind that Journal is not supported in the forum.

Newbie

Posts

Joined
Thu Mar 04, 2021 12:23 am

Post by straightlight » Wed Apr 07, 2021 1:23 am

If no extensions are provided as such from the Marketplace already, you could always create a new service request in the Commercial Support section of the forum to get this done as a custom job.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nbrofree » Wed Apr 07, 2021 3:30 am

Yeap, I will do that in time, if noone has some idea that could help or point me to the right direction.

Again, sincerely thanx for the help.

Newbie

Posts

Joined
Thu Mar 04, 2021 12:23 am

Post by ADD Creative » Wed Apr 07, 2021 5:25 am

Have you tried ?

Code: Select all

<![CDATA[(preg_replace('/\D/', '', $data['payment_postcode']))]]>
Have you checked the modification file to see it's being changed correctly?

www.add-creative.co.uk


Active Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by paulfeakins » Wed Apr 07, 2021 5:21 pm


For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Guru Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by Lopezis » Wed Apr 07, 2021 6:46 pm

To get started, a custom object is required in order to populate zip code records which will be used for reference. Depending on the zip code database you have access to or download from, the data points given may vary.

myprepaidcenter activation
Last edited by Lopezis on Thu Apr 08, 2021 2:01 pm, edited 1 time in total.

Newbie

Posts

Joined
Wed Apr 07, 2021 6:42 pm

Post by straightlight » Wed Apr 07, 2021 7:45 pm

Better to use the Restrict Payment Methods from Johnathan on the Marketplace in order to use such restrictions whereas specific countries would need to have reformulated postcodes prior to reach the service provider's electronically during checkout or from the admin orders API.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 44 guests