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

Post by giantherbs » Thu Jun 13, 2019 12:04 am

So, I have a question about this. I have added two custom fields. One is a yes or no question (select | address), the other is a text field (text | address). They can be seen when a customer creates a new account in check out, but if they simply "register" without purchasing an item, the custom fields are not there. This is question 1, how does one make the custom fields appear in the simple registration section.

Question 2 is: I can not see the answers to the questions in the admin customer page here /store/admin/index.php?route=customer/customer/edit&user_token... I looked in the Database table, and under the customer table, the custom_field column simply shows "[]" -- so I am wondering where the custom answers are being stored....It looks like in the DB there are five table associated with the Custom Field:
oc_custom_field
oc_custom_field_customer_group
oc_custom_field_description
oc_custom_field_value
oc_custom_field_value_description
But all of these simply store the question but not the answer.
I would like to be able to see the answers to the questions on the customer form in the admin section, so that I can validate an account manually. So the question I have is: Am I missing a table? Am I missing a join of the answer field to the user table? How come the DB simply stores a "[]" in the user table, and if there is more than one custom field, shouldn't there be multiple columns to store this information?

I have looked at the above posts, and I did change the code to follow both the solution here https://github.com/opencart/opencart/bl ... _field.php
and here https://github.com/opencart/opencart/tr ... roller/api
but I have not noticed a change in being able to see the answers in the admin page....

So am I missing something?

Newbie

Posts

Joined
Fri Apr 26, 2019 11:15 am

Post by straightlight » Thu Jun 13, 2019 12:18 am

So am I missing something?
Yes, you are but it's fresh information. Since yesterday, a massive patch release change has been unofficially released, it is still in pending state. See if the following changes works. Obviously, each $this->url->link lines may require some change ending with lines:

Code: Select all

'&language=' . $this->config->get('config_language')
to read:

Code: Select all

true
in this case if you're not using the Github version.

See this solution: https://github.com/engwalid1974/opencar ... 4bc74985b3 and follow the FAQ afterwards: viewtopic.php?f=176&t=200804#p718325 and see if the custom fields do work as intended.

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 giantherbs » Thu Jun 13, 2019 11:31 am

Thanks for that. I am looking at the github now. It appears that the - is the code removed and the + is the code added? Meaning this is not a cut and paste the whole section situation.... Just making sure I am reading it right...

Newbie

Posts

Joined
Fri Apr 26, 2019 11:15 am

Post by straightlight » Thu Jun 13, 2019 9:12 pm

Simply look at the filenames on top of each blocks of information. Then, copy them over your existing files on a test environment in order to test it. Then, clear out your OC cache by following the forum rules: viewtopic.php?f=176&t=200804#p718325

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 giantherbs » Thu Jun 13, 2019 11:00 pm

Well, on first try of adding the new code, it broke my customer form. so I have reverted to my original format. I am running version 3.0.2.0, but I notice that there are some files that are in the page here (https://github.com/engwalid1974/opencar ... 4bc74985b3) that are not in my version, (for example this file upload/admin/controller/marketing/affiliate.php is not in my marketing folder) and the line numbering is significantly different throughout the files. What is the current version that this update is based on, or how far behind am I for versions? And is there a page where I could start at that tells me the files that I would need to update to get current with the current version, before I apply these changes on the custom form update page? It would be much easier to find the correct pieces to add to if I was "on the same page" as the current version as they say. I will give it another stab later, but will create .bck versions of everything this go around. Thanks for the help Straightlight.

Newbie

Posts

Joined
Fri Apr 26, 2019 11:15 am

Post by straightlight » Thu Jun 13, 2019 11:09 pm

What is the current version that this update is based on
The Github version (master branch).
or how far behind am I for versions?
Not too far but I'd still recommend to upgrade to the latest version (v3.0.3.2) since more features and bug fixes were added in it.
And is there a page where I could start at that tells me the files that I would need to update to get current with the current version, before I apply these changes on the custom form update page?
As I said on the above reply, each files are already listed accordingly to process the change.
It would be much easier to find the correct pieces to add to if I was "on the same page" as the current version as they say. I will give it another stab later, but will create .bck versions of everything this go around.
The next version is already planned ahead to be released, hopefully, with these modifications but are still under evaluations since major issues with custom fields have been tracked down recently and we're working on resolving those issues as soon as humanly possible. If you can't wait for the next release, however, as this integration for you must be done by urgency, send me a PM and I could probably do this as a custom job to integrate this with compatibility management.

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