For VM 3.4.3.10014 on JL 3.9.3.
Simulate issue:
1. Define new customfield, string with name ‘Size’.
2. Add this new customfield to some product and with value 0, in this case, the value Size is 0.
3. Add this new customfield to some product and with value 2, in this case, the value Size is 2.
3. Save product.
Error:
If you see the product modified, in the Size atribute only show 2 option into combo: " " (first option empty) and 2 (second option). Don't see 0 in the first option.
Debug:
This value 0 (as string) isn’t saving into table _virtuemart_product_customfields and its _customfield_value field is empty.
Solution:
You have to modify the code to correct this data management and change code in 3 files:
FIRST: In administrator part to save data of custom field:
administrator/components/com_virtuemart/helpers/vmtable.php line 510
Change these lines:
// Bind the source value, excluding the ignored fields.
foreach ($this->getProperties() as $k => $v)
{
// Only process fields not in the ignore array.
if (!in_array($k, $ignore))
{
if (isset($src[$k]))
{
$this->$k = $src[$k];
}
}
}
To others one:
// Bind the source value, excluding the ignored fields.
foreach ($this->getProperties() as $k => $v)
{
// Only process fields not in the ignore array.
if($k=="customfield_value"){
if (!in_array($k, $ignore, true)) {
if (isset($src[$k])) {
$this->$k = $src[$k];
}
}
}else {
if (!in_array($k, $ignore)) {
if (isset($src[$k])) {
$this->$k = $src[$k];
}
}
}
}
At least, check type ‘in_array’ when $k is ‘customfield_value’.
So, save the value of customfield.
I don’t know if this change will have to apply in functions in this same file(possibly):
checkDataContainsTableFields
bindTo
It's a task for VM support/dev.
SECOND: In administrator part to read data of custom field:
administrator/components/com_virtuemart/models/customfields.php line 338
Change these lines:
$field->customfield_value = empty($field->customfield_value) ? $field->custom_value : $field->customfield_value;
To others one:
if($field->field_type=="S"){
$field->customfield_value = isset($field->customfield_value) ? $field->customfield_value : $field->custom_value;
}else {
$field->customfield_value = empty($field->customfield_value) ? $field->custom_value : $field->customfield_value;
}
So, read the value of customfield.
THIRD: In component part to show data of custom field (product detaild view to user):
components/com_virtuemart/sublayouts/customfield.php line 56
Change these lines
$customfield->customfield_value = empty($customfield->customfield_value) ? $customfield->custom_value : $customfield->customfield_value;
To others one:
if($customfield->field_type=="S"){
$customfield->customfield_value = isset($customfield->customfield_value) ? $customfield->customfield_value : $customfield->custom_value ;
}else {
$customfield->customfield_value = empty($customfield->customfield_value) ? $customfield->custom_value : $customfield->customfield_value;
}
So, user can see the value of customfield into productdetails view.
REQUEST:
I do not know if it is the best solution but it works, and I would like development to implement the best solution for this issue in the next subreleased VM.