Hello,
I've enabled debug.
So some things become clear but another not.
The name of the plugin in hikashop documentation is not right : it's not OnBeforeUserCreate but onUserBeforeSave.
Moreover the parameters seems not be references.
My code is now like that :
class plgHikashopCode_ent extends JPlugin
{
function plgHikashopCode_ent(&$subject, $config){
parent::__construct($subject, $config);
if(!isset($this->params)){
$plugin = JPluginHelper::getPlugin('hikashop', 'code_ent');
if(version_compare(JVERSION,'2.5','<')){
jimport('joomla.html.parameter');
$this->params = new JParameter($plugin->params);
} else {
$this->params = new JRegistry($plugin->params);
}
}
}
function onUserBeforeSave($element,$element2,$element3) {
//var_dump($element);
//var_dump($element2);
var_dump($element3);
$database = JFactory::getDBO();
$query='SELECT count(*) FROM entreprises WHERE code = "'.$element3->code_entreprise.'"';
$database->setQuery($query);
$database->query();
$num_rows = $database->loadResult();
var_dump($num_rows);
$count_rows=(int)$num_rows;
if ($count_rows <= 0)
{
if ($element3->code_entreprise != '')
{
$app = JFactory::getApplication();
$app->enqueueMessage('Votre code entreprise est inconnu');
}
$do=false;
}
}
}
The plugin is called. But element->code_entreprise not known. That's errors on die showing var_dump($element3) :
array(21) { ["isRoot"]=> NULL ["id"]=> int(0) ["name"]=> string(4) "Test" ["username"]=> string(4) "test" ["email"]=> string(24) "christelle.simon@free.fr" ["password"]=> string(34) "$P$DESPKGG4SCCPVTRjWg3uTqxMK9p83C1" ["password_clear"]=> string(8) "12345678" ["usertype"]=> NULL ["block"]=> NULL ["sendEmail"]=> int(0) ["registerDate"]=> string(19) "2014-04-29 06:37:44" ["lastvisitDate"]=> NULL ["activation"]=> NULL ["params"]=> string(44) "{"site_language":"fr-FR","language":"fr-FR"}" ["groups"]=> array(1) { [2]=> string(1) "2" } ["guest"]=> int(1) ["lastResetTime"]=> NULL ["resetCount"]=> NULL ["aid"]=> int(0) ["password2"]=> string(8) "12345678" ["gid"]=> string(1) "0" } Notice: Trying to get property of non-object in /var/www/vhosts/fair-play.fr/subdomains/cerise/httpdocs/plugins/hikashop/code_ent/code_ent.php on line 34 string(1) "0" Notice: Trying to get property of non-object in /var/www/vhosts/fair-play.fr/subdomains/cerise/httpdocs/plugins/hikashop/code_ent/code_ent.php on line 45
Code entreprise is a custom field. This is a part of identification page :
<tr id="hikashop_user_code_entreprise" class="hikashop_registration_code_entreprise_line">
<td class="key">
<td>
<input id="code_entreprise" class="inputbox" type="text" value="sdfsdf" name="data[user][code_entreprise]" onchange="hikashopToggleFields(this.value,'code_entreprise','user',0);">
<span class="hikashop_field_required">*</span>
</td>
</tr>
Maybe, I'm wrong in calling parameters ?
Best Regards