VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: sandomatyas on October 14, 2019, 17:44:58 PM

Title: Get customfield values progmatically
Post by: sandomatyas on October 14, 2019, 17:44:58 PM
What is the proper way to get the value of the custom fields of the product when I have only a virtuemart_product_id? getProduct() doesn't show it when it's a plugin type field. How should I fetch this data from VM API?
Title: Re: Get customfield values progmatically
Post by: PRO on October 14, 2019, 21:30:42 PM
from where?


I USE

// gets a product param from single plugin
//$product , $param_name
function getParam($product,$param,$separated=''){
$return='';
   if   (!empty($product->customfieldsSorted['addtocart']))   {
     foreach ($product->customfieldsSorted['addtocart'] as $field) {
     if (!empty($field->$param)){
     $split='';
     if ($return!=''){$split=$separated;}
    $return.=$split.$field->$param;}

    }

    }
    return $return;
}


THEN.  ON PRODUCT PAGE
$labels=getParam($this->product,'PARAMETER-NAME',',');

IF on the category page or anywhere else, you would change

$this->product   to    $product