I have two different custom plugins.
I open product, insert one of two plugin field, select parameter and save, then two both plugins display its fields inside the form.
plgVmOnProductEdit triggers are below.
1 (article.php):
<?php
class plgVmCustomArticle extends vmCustomPlugin {
function plgVmOnProductEdit($field, $product_id, &$row,&$retValue) {
$this->parseCustomParams($field);
if(!isset($field->custom_category)){
$retValue .= 'Ошибка в настойках<br />';
return true ;
}
$options=array();
$db = JFactory::getDBO();
$q = 'SELECT * FROM #__content WHERE `catid`='.((int) $field->custom_category);
$db->setQuery($q);
$result = $db->loadObjectList();
if($result){
$retValue .= 'Выберите статью из списка<br />';
$retValue .= '<select name="custom_param['.$row.'][custom_article]">';
foreach($result as $o){
$retValue .= '<option value="'.$o->id.(
isset($field->custom_article)&&($o->id==$field->custom_article)?
'" selected="selected':''
).'">'.$o->title.'</option>';
}
$retValue .= '</select><br />';
}else{
$q = 'SELECT `title` FROM #__categories WHERE `id`='.((int) $field->custom_category);
$db->setQuery($q);
$result = $db->loadObject();
if($result)
$retValue .= 'В категории'.$result->title.' статьи отсутствуют<br />';
else
$retValue .= 'Категория №'.((int) $field->custom_category).' отсутствует<br />';
}
return true ;
}
}
2 (series.php)
<?php
class plgVmCustomSeries extends vmCustomPlugin {
function plgVmOnProductEdit($field, $product_id, &$row, &$retValue){
$options=array();
$db = JFactory::getDBO();
$db->setQuery('SELECT `id`, CONCAT(`mf_name`, ": ", `name`) as "name" FROM `#__virtuemart_series` a LEFT JOIN `#__virtuemart_manufacturers_'.VmConfig::get('vmlang').'` USING(`virtuemart_manufacturer_id`) WHERE a.`published`=1');
$result = $db->loadObjectList();
$db->setQuery('SELECT `id` FROM `#__virtuemart_product_custom_plg_series` WHERE `virtuemart_product_id`='.$product_id);
$id = $db->loadResult();
if($result){
$retValue .= 'Выберите серию товара из списка<br />';
$retValue .= '<select name="virtuemart_product_series"><option value="0"'.(
!$id?
' selected="selected"':''
).'>Не установлена</option>';
foreach($result as $o){
$retValue .= '<option value="'.$o->id.(
$o->id==$id?
'" selected="selected':''
).'">'.$o->name.'</option>';
}
$retValue .= '</select><br />';
}else{
$retValue .= $db->getErrorMsg();
}
return true ;
}
}
What have I did wrong?
The problem is solved!
The plgVmOnProductEdit must start form this code:
<?php ...
if ($field->custom_element != $this->_name) return '';
If it would have written in http://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins , I would have saved my time.