Post by tbl » Mon Feb 05, 2018 3:47 am

OC 3.0.2.0 clean install

Required custom field is incorrectly blocking manual order adding (sale/order/add)

This is what I did to obtain this problem:

1.) I did a clean install of OC 3.0.2.0

2.) I added a new custom field with these settings:
(see attachment error01.png)
Name: test
Location: account (but address does have the same problem)
Type: text (textarea and others does have the same problem)
Customer Group: Checked default
Required: Checked default
Status: Enabled
Order: 0

3.) Sale > Orders > Add new

4.) Filled in all the required fields on Customer Details tab, but OC displays a message the custom field is required when pressing continue.
(see attachment error02.png)

The seems to be something wrong with the field validation.

Attachments

error02.png

error02.png (73.4 KiB) Viewed 1140 times

error01.png

error01.png (59.41 KiB) Viewed 1140 times


tbl
Newbie

Posts

Joined
Thu Feb 01, 2018 4:24 am

Post by straightlight » Mon Feb 05, 2018 5:40 am

The catalog/controller/api/customer.php file requires that you use validation with regular expression whenever the text type with account location is created. In your case, the regular expression is empty. The validation process is the following when a custom field is set as required and / or as text field:
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']);
}
}
}
In order to debug which condition does not apply with your created custom field, from the code above, you could add:

Code: Select all

$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the first IF statement!');
below the first instance of:

Code: Select all

$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
of that sentence.

Then, below the second instance of that same sentence, you could add:

Code: Select all

$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the second IF statement!');
Then, refresh your order add page and see again if you can validate the field. Obviously, you might not be able to which is what we're expecting in this case. Then, go to your admin - > system - > maintenance - > error logs page. See for a sentence at the bottom of your logs that contains:
from the first IF statement!
or:
from the second IF statement!
noticing which one will appear.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 robutt » Tue Feb 06, 2018 4:48 pm

I have the same problem.
Tested it, and the errorlog says: "from the first statement!".
So, it goed wrong when it is required at the account-page. That's correct, that's what TBL and I have entered as CustomField.

I don't see why the IF-statement gives an error. The POST looks to be empty...?

Newbie

Posts

Joined
Thu Oct 26, 2017 5:14 pm

Post by straightlight » Wed Feb 07, 2018 6:22 am

robutt wrote:
Tue Feb 06, 2018 4:48 pm
I have the same problem.
Tested it, and the errorlog says: "from the first statement!".
So, it goed wrong when it is required at the account-page. That's correct, that's what TBL and I have entered as CustomField.

I don't see why the IF-statement gives an error. The POST looks to be empty...?
The same problem might be the case but no screenshot has been posted with your current custom fields configuration from the admin.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 robutt » Wed Feb 07, 2018 3:58 pm

My custom-fields-config is the same (ok, my fieldname is not 'test' but 'companyname'.).
I don't see why I should place a screenshot with it. But it's ok, we can wait till TS shows up with his tests...

Newbie

Posts

Joined
Thu Oct 26, 2017 5:14 pm

Post by tbl » Thu Feb 08, 2018 6:54 am

My OC installation is logging the same as robutt

2018-02-07 22:49:52 - VAT-number required! from the first IF statement!

For now I can work with it to set it on not required. But how to solve this issue?

tbl
Newbie

Posts

Joined
Thu Feb 01, 2018 4:24 am

Post by straightlight » Thu Feb 08, 2018 7:00 am

From the instructions above, replace:

Code: Select all

$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the first IF statement!');
with:

Code: Select all

$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the first IF statement . POST Size: ' . sizeof($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']]) . '!');
And:

Code: Select all

$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the second IF statement!');
with:

Code: Select all

$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the second IF statement . POST Size: ' . sizeof($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']]) . '!');
Try the API again and see what debug message will be provided this time.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 tbl » Thu Feb 08, 2018 7:11 am

2018-02-07 23:09:52 - PHP Notice: Undefined index: account in #/public_html/catalog/controller/api/customer.php on line 73
2018-02-07 23:09:52 - VAT-number required! from the first IF statement . POST Size: 0!

tbl
Newbie

Posts

Joined
Thu Feb 01, 2018 4:24 am

Post by straightlight » Thu Feb 08, 2018 7:25 am

Then, there is a clue. In catalog/controller/api/customer.php file,

replace:

Code: Select all

if ($custom_field['location'] == 'account') {
with:

Code: Select all

if (isset($custom_field['location']) && html_entity_decode(trim(strtolower($custom_field['location'])), ENT_QUOTES, 'UTF-8') == 'account') {

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 tbl » Fri Feb 09, 2018 3:52 am

Sorry Straightlight, still got the same error.

tbl
Newbie

Posts

Joined
Thu Feb 01, 2018 4:24 am

Post by straightlight » Fri Feb 09, 2018 6:08 am

Revert the changes. Then, replace this entire block of code:

Code: Select all

// Custom field validation
			$this->load->model('account/custom_field');

			$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);

			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']);
					}
				}
			}
			
with:

Code: Select all

// Custom field validation
			if ($customer_group_id) {
				$this->load->model('account/custom_field');

				$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);

				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']);
						}
					}
				}
				
			} else {
				$json['error']['warning'] = $this->language->get('error_customer_group');
			}
In catalog/language/en-gb/api/customer.php file,

add at the bottom of the file:

Code: Select all

$_['error_customer_group'] = 'Either the selected customer group or the default customer group could not be associated with the order!';
Then, try again.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 tbl » Fri Feb 09, 2018 6:44 am

Nope, still the same.

Also the error message "VAT-number is required" is the same and isn't changed in your new "error_customer_group".

Can't you reproduce it on a demo store?

tbl
Newbie

Posts

Joined
Thu Feb 01, 2018 4:24 am

Post by straightlight » Fri Feb 09, 2018 7:16 am

Then, the issue is not with the customer group ID. Below:

Code: Select all

$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
add:

Code: Select all

$this->log->write('CUSTOM_FIELDS :: DEBUG :: ' . print_r($custom_fields));
Then, try again and afterwards go to your admin - > systems - > maintenance - > error logs page. Look for lines beginning with: CUSTOM_FIELDS :: DEBUG :: .

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 tbl » Fri Feb 09, 2018 7:32 am

It's related to a required field, not a specific customer group.
Every customer group is showing this error when set it on required.
When not requiring a field everyting works just fine.

Code: Select all

2018-02-08 23:28:39 - CUSTOM_FIELDS :: DEBUG :: 1

tbl
Newbie

Posts

Joined
Thu Feb 01, 2018 4:24 am

Post by straightlight » Fri Feb 09, 2018 7:38 am

tbl wrote:
Fri Feb 09, 2018 7:32 am
It's related to a required field, not a specific customer group.
Every customer group is showing this error when set it on required.
When not requiring a field everyting works just fine.

Code: Select all

2018-02-08 23:28:39 - CUSTOM_FIELDS :: DEBUG :: 1
I did encountered odd returns from boolean statements compared to the use of integers since using PHP v5.6+ or PHP 7+ when coding custom projects.

Let's see if the following adjustment works. In your catalog/model/account/custom_field.php file,

find:

Code: Select all

'required'           => empty($custom_field['required']) || $custom_field['required'] == 0 ? false : true,
replace with:

Code: Select all

'required'           => empty($custom_field['required']) || $custom_field['required'] == 0 ? 0 : 1,

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 tbl » Sat Feb 10, 2018 3:03 am

Tested it but the error is still there.

tbl
Newbie

Posts

Joined
Thu Feb 01, 2018 4:24 am

Post by straightlight » Sat Feb 10, 2018 6:38 am

PM sent.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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 1:42 am

Bug confirmed. Thanks for posting this issue.

@All users reading this, apply this fix: viewtopic.php?f=201&t=202036#p713641

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted 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: Baidu [Spider] and 4 guests