An error occurred with the OpenCart 3 module I installed, But I can’t contact the developer.
Can anyone help me check the code?
` foreach ($custom_fields as $custom_field_id => $value) { # line 48
// $value can be raw value or custom_field_value_id
// depending on type of custom field
if (!isset(self :: $custom_field_data[ $custom_field_id ])) {
continue;
}
$custom_field = self :: $custom_field_data[ $custom_field_id ];
if ($custom_field['location'] != $location) {
continue;
}
if (in_array($custom_field['type'], ['select', 'radio'])) {
if (isset($custom_field['custom_field_value'][ (int)$value ])) {
$custom_field_value = $custom_field['custom_field_value'][ (int)$value ];
$custom_fields_data[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'name' => $custom_field['name'],
'value' => $custom_field_value['name'],
'sort_order' => $custom_field['sort_order']
);
}
}
if ('checkbox' == $custom_field['type'] && is_array($value)) {
foreach ($value as $custom_field_value_id) {
if (isset($custom_field['custom_field_value'][ (int)$custom_field_value_id ])) {
$custom_field_value = $custom_field['custom_field_value'][ (int)$custom_field_value_id ];
$custom_fields_data[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'name' => $custom_field['name'],
'value' => $custom_field_value['name'],
'sort_order' => $custom_field['sort_order']
);
}
}
}
if ('file' == $custom_field['type']) {
$upload_info = $this->model_tool_upload->getUploadByCode($value);
if ($upload_info) {
$custom_fields_data[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'name' => $custom_field['name'],
'value' => $upload_info['name'],
'sort_order' => $custom_field['sort_order']
);
}
}
if (in_array($custom_field['type'], ['text', 'textarea', 'date', 'datetime', 'time'])) {
$custom_fields_data[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'name' => $custom_field['name'],
'value' => $value,
'sort_order' => $custom_field['sort_order']
);
}
}`
My usage environment:
php 7.3, 8.1
OpenCart 3.0.4.0
This is a module that can display a custom field on the order, If the user fills in the custom field, it can be displayed normally.
But if the user does not fill in the custom fields, the above error message will appear on the order:
Warning: Invalid argument supplied for foreach() in model/extension/cicustom_fields_display/custom_field.php on line 48
Can anyone help me?
Thank you!
SAGARA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.