Post by straightlight » Sun Feb 11, 2018 1:41 am

This post is for extension developers.
Post #2 is linked with post #3 for fixing the actual issue.

In catalog/controller/api/customer.php file,

find:

Code: Select all

foreach ($custom_fields as $custom_field) {
				if ($custom_field['location'] == 'account') { 
					if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					}
				}
			}
			
replace with:

Code: Select all

foreach ($custom_fields as $custom_field) {
				if ($custom_field['location'] == 'account') {
					foreach ($this->request->post['custom_field'] as $posted_key => $posted_value) {
						if ((int)$posted_key == (int)$custom_field['custom_field_id']) {
							if (empty($posted_value) && $custom_field['required']) {
								$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
							} elseif ((html_entity_decode(trim(strtolower($custom_field['type'])), ENT_QUOTES, 'UTF-8') == 'text') && !empty($custom_field['validation']) && !filter_var($posted_value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
								$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
							}
						}
					}
				}
			}
This should resolved the problem.
Last edited by straightlight on Mon Feb 12, 2018 2:47 am, edited 2 times in total.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by straightlight » Sun Feb 11, 2018 2:37 am

This line:

Code: Select all

if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
could also be replaced with:

Code: Select all

if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) {
and:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
for:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
rather than replacing the whole block. Although, not as easy to troubleshoot whenever there's a problem.
Last edited by straightlight on Sun Feb 11, 2018 4:28 am, edited 1 time in total.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by straightlight » Sun Feb 11, 2018 3:10 am

Another event that could happen is when OC administrators are logged in at the same time and one could simply delete a custom field while another could create an OC order and be prevented to proceed to the next step without realizing why.

In order to prevent this type of activity, in catalog/controller/api/customer.php file,

find:

Code: Select all

foreach ($custom_fields as $custom_field) {
add above:

Code: Select all

$custom_field_ids = array();

if (isset($this->request->post['custom_field'])) {
				foreach ($this->request->post['custom_field'] as $custom_field_id => $custom_field_values) {
					if (is_numeric($custom_field_id)) {
						$custom_field_ids[] = (int)$custom_field_id;
					}
				}
			}
Then, find:

Code: Select all

foreach ($custom_fields as $custom_field) {
				if ($custom_field['location'] == 'account') { 
					if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					}
				}
			}
replace with:

Code: Select all

foreach ($custom_fields as $custom_field) {
				if ($custom_field['location'] == 'account') { 
					if (!in_array((int)$custom_field['custom_field_id'], $custom_field_ids)) {
						$json['error']['warning'] = $this->language->get('error_custom_field_not_found');
						
						break;						
					} elseif ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					}
				}
			}
			
In catalog/language/en-gb/api/customer.php file, add at the bottom:

Code: Select all

$_['error_custom_field_not_found'] = 'One or many custom fields defined on this page have either been changed categorically or they have been removed by a top administrator. Please refresh the page and refill a new order!';
This should resolve the issue.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by straightlight » Mon Feb 12, 2018 2:47 am

Due to the 3 posts above, each posts objective have been clarified.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by straightlight » Sat Feb 24, 2018 8:19 pm

One of those fixes has been added on Github on the following files:

- catalog/controller/api/customer.php
- catalog/controller/api/payment.php
- catalog/controller/api/shipping.php

Ensure to replace them accordingly and to clear your OC caches afterwards (OC Admin!): https://github.com/opencart/opencart/tr ... roller/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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by kerim92 » Mon Mar 19, 2018 1:02 am

hi,
opencart version 3.0.2
Custom fileds are build and make it as text. and i make it as required.

when customer update custom field information from their account page, custom filelds are deleting. and text boxes being free.

i just appy your fix as you exactly write.
but still problem persist.

i just replaced files provided in your github link. but problem still there.


looking forward for help
thank you.



edit:
site using lastest version of journal theme.

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by straightlight » Mon Mar 19, 2018 1:32 am

- Clear your OC cache from your admin - > dashboard - > blue icon on the right - > clear both caches
- Clear your OC cache from your admin - > extensions - > modifications - > refresh button

after making these modifications. It is not because the issue does persist after making those changes.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by kerim92 » Mon Mar 19, 2018 2:41 am

hi sir,

both caches refreshed/cleared

still same problem.

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by straightlight » Mon Mar 19, 2018 3:46 am

Which one of these fixes on the topic did you chose? Have you tried the 2nd post?

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by straightlight » Mon Mar 19, 2018 4:28 am

On Github Opencart, replace the catalog/controller/api/customer.php , payment.php and shipping php files. Clear your OC cache from the OC admin afterwards.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by kerim92 » Mon Mar 19, 2018 1:37 pm

Hi,
i did this before but,
i just try again.
Github Opencart, replaced the catalog/controller/api/customer.php , payment.php and shipping php files and well cleared/refreshed all caches that you asked before.

still same problem.
it is saving custom fields during register. after made changes field being free. and it is deleting what i save before.


my website is: notebookchipset.com

note: i have backup of api folder as orginal files.

ps:i can send passwords if you want to investigate it.

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by straightlight » Mon Mar 19, 2018 7:27 pm

Cache issues.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by kerim92 » Wed Mar 21, 2018 5:36 pm

i just found problem.

i just clearly install opencart 3.0.2 my another hosting. i just try to edit custom field before making your changes. it is working like a charm.
no need to apply fix.

after install Journal2 theme problem is become.
custom field is not saving.
i just found this problem because of Journal theme. themes caching system also off. i just cleared journal cache too but it is not saving after install journal theme.

if anyone journal developer here please make a fix to your theme.

thank you straightlight for your help.

edit:
notebookchipset.com is a test server. not a real server. opencart 3.0.2 & journal theme installed for test purposes.

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by straightlight » Wed Mar 21, 2018 6:58 pm

i just clearly install opencart 3.0.2 my another hosting. i just try to edit custom field before making your changes. it is working like a charm.
no need to apply fix.
If no fix needs to be applied, then there would be no official report about it. If you did not needed to apply the fix, it means the fix was already applied with the new downloaded version of v3.0.2.0 that you have compared to the time period where the issue was actually reported by other users prior.

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.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


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 9 guests