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 (73.4 KiB) Viewed 3770 times
error01.png (59.41 KiB) Viewed 3770 times
In order to debug which condition does not apply with your created custom field, from the code above, you could add: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']);
}
}
}
Code: Select all
$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the first IF statement!');
Code: Select all
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
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!');
or:from the first IF statement!
noticing which one will appear.from the second IF statement!
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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.robutt wrote: ↑Tue Feb 06, 2018 4:48 pmI 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...?
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Code: Select all
$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the first IF statement!');
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']]) . '!');
Code: Select all
$this->log->write($json['error']['custom_field' . $custom_field['custom_field_id']] . ' from the second IF statement!');
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']]) . '!');
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
replace:
Code: Select all
if ($custom_field['location'] == 'account') {
Code: Select all
if (isset($custom_field['location']) && html_entity_decode(trim(strtolower($custom_field['location'])), ENT_QUOTES, 'UTF-8') == 'account') {
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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']);
}
}
}
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');
}
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!';
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Code: Select all
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
Code: Select all
$this->log->write('CUSTOM_FIELDS :: DEBUG :: ' . print_r($custom_fields));
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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.tbl wrote: ↑Fri Feb 09, 2018 7:32 amIt'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
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,
Code: Select all
'required' => empty($custom_field['required']) || $custom_field['required'] == 0 ? 0 : 1,
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
@All users reading this, apply this fix: viewtopic.php?f=201&t=202036#p713641
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 29 guests