News:

Looking for documentation? Take a look on our wiki

Main Menu

Can't filter by custom fields with numeric value

Started by Ghost, January 24, 2023, 08:55:53 AM

Previous topic - Next topic

Ghost

Filtering by custom fields with integer-like values is broken. The select box is built using wrong values like this:

<select id="customfields108" name="customfields[108]" class="changeSendForm form-control vm-chzn-select">
<option value="" selected="selected">-- Select --</option>
<option value="1">2000</option>
<option value="2">4000</option>
</select>

This is because of array_merge() here which resets numeric keys:
https://dev.virtuemart.net/projects/virtuemart/repository/entry/trunk/virtuemart/components/com_virtuemart/views/category/view.html.php#L651

Changing that line to something like this seems to work:

$valueOptions = array('' => $emptyOption) + $valueOptions;

Another issue is that option with value 0 doesn't appear in select box at all and code related to 0 value is generally broken. This is because of liberal use of empty(). For example, in these places:
https://dev.virtuemart.net/projects/virtuemart/repository/entry/trunk/virtuemart/components/com_virtuemart/views/category/view.html.php#L643
https://dev.virtuemart.net/projects/virtuemart/repository/entry/trunk/virtuemart/administrator/components/com_virtuemart/models/product.php#L230
https://dev.virtuemart.net/projects/virtuemart/repository/entry/trunk/virtuemart/administrator/components/com_virtuemart/models/product.php#L411