VirtueMart version: 4.8.2 build 11343
Joomla: Joomla 5.4.8
PHP: 8.2.33
Database: 10.11.18-MariaDB
Problem
In VirtueMart Configuration → Shopfront → Sort & Search, the Available Sort-by fields settings cannot be saved in an all-unchecked state.
I want to disable all customer-facing Sort-by fields.
There are currently five available fields:
Product SKU
Category
Manufacturer name
Product Name
Ordering
If I uncheck all five fields and click Save, the configuration initially appears to save, but after reloading the configuration page, the five fields are checked again.
What I found
The problem appears to be related specifically to the case where all checkboxes are unchecked.
When one or more fields are selected, the checkbox group submits a value for:
browse_orderby_fields
However, when all checkboxes are unchecked, no browse_orderby_fields value is submitted by the form.
The VirtueMart configuration save code then merges the submitted form data with the default configuration from virtuemart.cfg.
The default configuration contains:
browse_orderby_fields=array:\p`.product_sku|category_name|mf_name|product_name|pc.ordering`
Because the checkbox field is absent from the POST data when all boxes are unchecked, the default value remains in the configuration instead of being replaced with an empty array.
Database test
I verified this directly in the #__virtuemart_configs table.
After manually changing:
browse_orderby_fields=["p.product_sku","category_name","mf_name","product_name","pc.ordering"]
to:
browse_orderby_fields=[]
the VirtueMart configuration page correctly displayed all five Sort-by fields as unchecked.
This confirms that VirtueMart can store and use an empty array correctly. The problem appears to be that the configuration Save process does not explicitly clear the setting when the checkbox array is absent from the submitted form.
Version testing
I initially encountered this behavior on VirtueMart 4.8.0.
I subsequently updated the site to VirtueMart 4.8.2 build 11343, but the behavior remains the same.
I also checked the 4.8.2 configuration model and controller. The controller passes the POST data to the configuration model, and the configuration model merges the submitted data with the configuration loaded from virtuemart.cfg.
Expected behavior
If an administrator unchecks all Available Sort-by fields and clicks Save, VirtueMart should save:
browse_orderby_fields=[]
and the five fields should remain unchecked after the configuration page is reloaded.
Actual behavior
If all five fields are unchecked and Save is clicked, the default five fields are restored after saving.
Why this matters
This prevents an administrator from disabling all customer-facing sorting options through the VirtueMart configuration interface.
In my particular case, this also causes VirtueMart category pages to generate sorting URLs such as:
/shop/valves/control-valves/by,product_sku
/shop/valves/control-valves/by,category_name
/shop/valves/control-valves/by,mf_name
/shop/valves/control-valves/by,product_name
/shop/valves/control-valves/by,ordering
These additional URLs were creating unwanted URL variants for the site.
Workaround
The configuration can be manually corrected in the database by setting:
browse_orderby_fields=[]
After doing this, VirtueMart correctly displays all Sort-by fields as unchecked.
However, this should not be necessary. The administrator should be able to save the setting through the normal VirtueMart configuration interface.
Could someone from the VirtueMart development team please confirm whether this is a bug and whether the configuration Save routine should explicitly handle an absent browse_orderby_fields checkbox array as an empty array?
Temporarily Solution
In administrator/components/com_virtuemart/models/config.php
immediately before:
$config->_params = array_merge($config->_params,$data);
this:
if (!array_key_exists('browse_orderby_fields', $data)) {
$data['browse_orderby_fields'] = array();
}