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

[Resolved] Custom plugins: all vmcustom plugins load in one fieldset

Started by MikUrrey, January 21, 2013, 13:45:59 PM

Previous topic - Next topic

MikUrrey

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 .= '&#1054;&#1096;&#1080;&#1073;&#1082;&#1072; &#1074; &#1085;&#1072;&#1089;&#1090;&#1086;&#1081;&#1082;&#1072;&#1093;<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 .= '&#1042;&#1099;&#1073;&#1077;&#1088;&#1080;&#1090;&#1077; &#1089;&#1090;&#1072;&#1090;&#1100;&#1102; &#1080;&#1079; &#1089;&#1087;&#1080;&#1089;&#1082;&#1072;<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 .= '&#1042; &#1082;&#1072;&#1090;&#1077;&#1075;&#1086;&#1088;&#1080;&#1080;'.$result->title.' &#1089;&#1090;&#1072;&#1090;&#1100;&#1080; &#1086;&#1090;&#1089;&#1091;&#1090;&#1089;&#1090;&#1074;&#1091;&#1102;&#1090;<br />';
else
$retValue .= '&#1050;&#1072;&#1090;&#1077;&#1075;&#1086;&#1088;&#1080;&#1103; &#8470;'.((int) $field->custom_category).' &#1086;&#1090;&#1089;&#1091;&#1090;&#1089;&#1090;&#1074;&#1091;&#1077;&#1090;<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 .= '&#1042;&#1099;&#1073;&#1077;&#1088;&#1080;&#1090;&#1077; &#1089;&#1077;&#1088;&#1080;&#1102; &#1090;&#1086;&#1074;&#1072;&#1088;&#1072; &#1080;&#1079; &#1089;&#1087;&#1080;&#1089;&#1082;&#1072;<br />';
$retValue .= '<select name="virtuemart_product_series"><option value="0"'.(
!$id?
' selected="selected"':''
).'>&#1053;&#1077; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;&#1072;</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?

MikUrrey

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.