I have a function that I've finally managed to create a user in Joomla & Virtuemart and saves all of the user data, however I can't get it to send a registration email... here's the function:
function create_user($data = NULL){
$user = array();
$user['fullname'] = $data['name'];
$user['email'] = $data['email'];
$user['password'] = $data['password'];
$user['username'] = $data['username'];
$instance = JUser::getInstance();
jimport('joomla.application.component.helper');
$config = JComponentHelper::getParams('com_users');
// Default to Registered.
$defaultUserGroup = $config->get('new_usertype', 2);
$instance->set('id', 0);
$instance->set('name', $user['fullname']);
$instance->set('username', $user['username']);
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$password_clear = $user['password'];
$crypted = JUserHelper::getCryptedPassword($password_clear, $salt);
$password = $crypted.':'.$salt;
$instance->set('password', $password);
$instance->set('password_clear',$password_clear);
$instance->set('email', $user['email']);
$instance->set('usertype', 'deprecated');
$instance->set('groups', array($defaultUserGroup));
//If autoregister is set let's register the user
$autoregister = NULL;
if(isset($options['autoregister'])){
$autoregister = $options['autoregister'];
}else{
$autoregister = $config->get('autoregister', 1);
}
if ($autoregister) {
if (!$instance->save()) {
return false;
}
else{
if(!class_exists('VmConfig')) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
if(!class_exists('shopFunctionsF')) require(JPATH_VM_SITE.DS.'helpers'.DS.'shopfunctionsf.php');
$config = VmConfig::loadConfig();
$db = JFactory::getDBO();
$customer_nr = uniqid(rand());
$my_id = $instance->get('id');
$data['virtuemart_user_id'] = $my_id;
$query = "INSERT INTO #__virtuemart_vmusers (virtuemart_user_id, customer_number,perms,created_on)
VALUES (".$my_id.", '".$customer_nr."', '".$data['perms']."', '".time()."')";
$queries = array(); array_push($queries,$query);
$db->setQuery($query);
if($db->query()){
$id = $my_id;
$query = "INSERT INTO #__virtuemart_userinfos
(address_type,virtuemart_user_id,address_type_name,name,company,last_name,first_name,phone_1,
address_1,address_2,city,virtuemart_state_id,virtuemart_country_id,zip,
created_on,vm_companyindustry,job_title)
VALUES ('BT',$id,'-default-','{$data['name']}','{$data['company']}','{$data['last_name']}',
'{$data['first_name']}','{$data['phone_1']}','{$data['address_1']}','{$data['address_2']}'
,'{$data['city']}','{$data['virtuemart_state_id']}','{$data['virtuemart_country_id']}',
'{$data['zip']}','".time()."','{$data['vm_companyindustry']}','{$data['job_title']}')";
array_push($queries,$query);
$db->setQuery($query);
if($db->query()){
$query = "INSERT INTO #__virtuemart_vmuser_shoppergroups
(virtuemart_user_id, virtuemart_shoppergroup_id)
VALUES ($id,'{$data['virtuemart_shoppergroup_id']}')";
array_push($queries,$query);
$db->setQuery($query);
if($db->query()){
$user_model = VmModel::getModel('user');
$u = $user_model->getCurrentUser();
$u->store($_POST);
shopFunctionsF::renderMail('mail_html_reguser', $data['email'], $data);
//$u->sendRegistrationEmail($u,"4borrell",false);
return "worked";
}
else{
return "After shoppergroups ".$db->query().print_r($queries,true);
}
}
else{
return "Error after userinfos".$db->query().print_r($queries,true);
}
}
else{
return "Error after vmusers".$db->query().print_r($queries,true);
}
}
}
else {
$instance->set('tmp_user', true);
}
}
This is the part about the email:
if($db->query()){
$user_model = VmModel::getModel('user');
$u = $user_model->getCurrentUser();
$u->store($_POST);
shopFunctionsF::renderMail('mail_html_reguser', $data['email'], $data);
//$u->sendRegistrationEmail($u,"4borrell",false);
return "worked";
}
Could anyone help with how to send the registration email programmatically? The current line throws a Jooml Error for view not found. The commented out line just gives an internal server error.