Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0.x.x] Disabled custom fields are displayed when editing customer in admin #13858

Closed
akaunderr opened this issue Apr 15, 2024 · 0 comments
Closed

Comments

@akaunderr
Copy link

akaunderr commented Apr 15, 2024

While editing customer through the admin, the disabled custom fields are still displayed, see the code below:

$data['custom_fields'][] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']),
'name' => $custom_field['name'],
'value' => $custom_field['value'],
'type' => $custom_field['type'],
'location' => $custom_field['location'],
'sort_order' => $custom_field['sort_order']
);
if($custom_field['type'] == 'file') {
if(isset($data['account_custom_field'][$custom_field['custom_field_id']])) {
$code = $data['account_custom_field'][$custom_field['custom_field_id']];
$upload_result = $this->model_tool_upload->getUploadByCode($code);
$data['account_custom_field'][$custom_field['custom_field_id']] = array();
if($upload_result) {
$data['account_custom_field'][$custom_field['custom_field_id']]['name'] = $upload_result['name'];
$data['account_custom_field'][$custom_field['custom_field_id']]['code'] = $upload_result['code'];
} else {
$data['account_custom_field'][$custom_field['custom_field_id']]['name'] = "";
$data['account_custom_field'][$custom_field['custom_field_id']]['code'] = $code;
}
}
foreach($data['addresses'] as $address_id => $address) {
if(isset($address['custom_field'][$custom_field['custom_field_id']])) {
$code = $address['custom_field'][$custom_field['custom_field_id']];
$upload_result = $this->model_tool_upload->getUploadByCode($code);
$data['addresses'][$address_id]['custom_field'][$custom_field['custom_field_id']] = array();
if($upload_result) {
$data['addresses'][$address_id]['custom_field'][$custom_field['custom_field_id']]['name'] = $upload_result['name'];
$data['addresses'][$address_id]['custom_field'][$custom_field['custom_field_id']]['code'] = $upload_result['code'];
} else {
$data['addresses'][$address_id]['custom_field'][$custom_field['custom_field_id']]['name'] = "";
$data['addresses'][$address_id]['custom_field'][$custom_field['custom_field_id']]['code'] = $code;
}
}
}
}

if (($custom_field['location'] == 'account') && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['location'] == 'account') && ($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'])))) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}

if (($custom_field['location'] == 'address') && $custom_field['required'] && empty($value['custom_field'][$custom_field['custom_field_id']])) {
$this->error['address'][$key]['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['location'] == 'address') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($value['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
$this->error['address'][$key]['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}

if (($custom_field['location'] == 'affiliate') && $custom_field['required'] && empty($this->request->post['custom_field']['affiliate'][$custom_field['custom_field_id']])) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['location'] == 'affiliate') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field']['affiliate'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}

All this should be wrapped up with a condition

if ($custom_field['status']) {
...
}

Or use something such as:

if (!$custom_field['status']) {
	continue;
}
@akaunderr akaunderr changed the title [3.0.x.x] Disabled custom fields are displayed when editing customer addresses in admin [3.0.x.x] Disabled custom fields are displayed when editing customer in admin Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants