Skip to Content

New J2Commerce 6.6.5 is out. Here is everything in the release.

See What’s New
Account
Enter the email address on your account.
Forgot your username?
Enter your password.
Forgot your password?

Or continue with

Closed Public Category: Technical Support / Bugs Ticket #1034

Custom field options with value/label 0 are dropped on save (radio/select/checkbox)

This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

J2Commerce

Version
J2Commerce v6

Conversation

Fred Oliver

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

Adam Melcher Staff

Fred,

Thanks for bringing this to our attention - I can confirm it is a valid issue and working on the fix in time for the upcoming release.

 

Adam