News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

New custom field shows up at old orders

Started by Kuubs, September 01, 2022, 10:51:35 AM

Previous topic - Next topic

Kuubs

Hello,

Really strange behaviour from Virtuemart. I have made a new custom field which shows up at older orders. How is that possible???

If I check the custom_params of the order items it displays the following:

{
    "30": "1514",
    "26": [],
    "27": [],
    "31": "1473"
   
}

The custom field id of the new custom field is 35, so it's pretty weird it shows the custom field that i just created. Can someone explain what is going on here?

OK I think because the custom_params are not having the 35 it just auto opts in to display it. Which is weird, but for som reason it does it. Anyone know how to fix this? Maybe I can add some code somewhere?

EDIT:

Ok I checked the customfield.php file which handles the custom fields. The weird thing is this piece of code:

//vmdebug('renderCustomfieldsCart $variantmods',$variantmods);
$productCustoms = array();
foreach( (array)$product->customfields as $prodcustom){

//We just add the customfields to be shown in the cart to the variantmods
if(is_object($prodcustom)){

//We need this here to ensure that broken customdata of order items is shown updated info, or at least displayed,
if($prodcustom->is_cart_attribute or $prodcustom->is_input){

//The problem here is that a normal value and an array can be valid. The function should complement, or update the product. So we are not allowed
//to override existing values. When the $variantmods array is not set for the key, then we add an array, when the customproto is used more than one time
if(!isset($variantmods[$prodcustom->virtuemart_custom_id])){
$variantmods[$prodcustom->virtuemart_custom_id][$prodcustom->virtuemart_customfield_id] = $prodcustom->virtuemart_customfield_id;
}
//the missing values are added with an own key.
if( is_array($variantmods[$prodcustom->virtuemart_custom_id]) and
!isset($variantmods[$prodcustom->virtuemart_custom_id][$prodcustom->virtuemart_customfield_id]) ){

$variantmods[$prodcustom->virtuemart_custom_id][$prodcustom->virtuemart_customfield_id] = $prodcustom->virtuemart_customfield_id;
}
}

$productCustoms[$prodcustom->virtuemart_customfield_id] = $prodcustom;
}
}


At first the $variantmods contain the actual custom_params of the order. And then with the following code other custom fields get added. The problem lies here that it just checks if it's a cart custom fields, it does not check whether or not the custom field is in the custom_params of the variantmods. This is a major bug I think.

Ok for everyone that has this bug/problem whatever you call it. I have found a fix. You can add this to the customfield.php file in your template override:

if(count($customfield_ids) > 1){
continue;
}


This checks whether or not the customfield array has more values than 1 (only 1 should be there if it's a valid option that is chosen) it just continue in the display, which skips the display altogether.

You can find this on line code 739:

foreach ( (array)$variantmods as $i => $customfield_ids) {

if(!is_array($customfield_ids)){
$customfield_ids = array( $customfield_ids =>false);
}

if(count($customfield_ids) > 1){
continue;
}