When creating/editing a custom field of type radio, singledropdown or checkbox, any option whose label (or value) is 0 is silently discarded on save. A typical Yes/No radio (0 = No, 1 = Yes) ends up storing only the 1 option.
Steps to reproduce
1. Admin → J2Commerce → Custom Fields → New.
2. Type = Radio. Add two options:
- Value 0, Name No
- Value 1, Name Yes
3. Save.
4. Re-open the field (or inspect #__j2commerce_customfields.field_value).
Expected
field_value = [{"value":"0","name":"No"},{"value":"1","name":"Yes"}] (both options kept).
Actual
The option with 0 is gone; e.g. field_value = [{"value":"1","name":"Yes"}]. A 0/No option can never be stored, which makes boolean-style radios impossible.
Root cause
In administrator/components/com_j2commerce/src/Model/CustomfieldModel.php, method save() (around line 388), options are filtered with:
$filtered = array_filter($data['field_value'], function ($row) {
return !empty($row['name']);
});
empty("0") returns true in PHP, so a row whose name is "0" is treated as empty and removed. (The same falsy-0 trap would also affect a value of 0 depending on how the row is keyed.)
Suggested fix
Use a strict empty-string check instead of empty(), testing value or label:
$filtered = array_filter($data['field_value'], static function ($row) {
$value = isset($row['value']) ? (string) $row['value'] : '';
$name = isset($row['name']) ? (string) $row['name'] : '';
return $value !== '' || $name !== '';
});
This keeps legitimate 0 options and still drops genuinely empty rows (both value and label empty).
Regards,
Fred