News:

Looking for documentation? Take a look on our wiki

Main Menu

Virtuemart user Registration from custom component

Started by BulletProof47, November 18, 2014, 11:53:32 AM

Previous topic - Next topic

BulletProof47

Hi everyone,I am creating a custom component.How can I create new user from my component.I tried this but its not working.
OR how can I create an api to create virtuemart user?

<?php
define
('_JEXEC'1);
defined('_JEXEC') or die( 'Restricted access' );
define('DS'DIRECTORY_SEPARATOR);
@
ob_start();
session_start();

if (
file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!
defined('_JDEFINES')) {
define('JPATH_BASE'dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once 
JPATH_BASE.'/includes/framework.php';
//JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'tables');
define('JPATH_VM_SITE'JPATH_ROOT.DS.'components'.DS.'com_virtuemart');
define('JPATH_VM_ADMINISTRATOR',JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart');
jimport('joomla.application.component.model');
require(
'administrator/components/com_virtuemart/models/user.php');
//$vmuser = new ('1');
$mdata = array
(
    
'email' => 'tssssest@yahoo.com',
    
'username' => 'tsssest@yahoo.com',
    
'name' => 'tesstuser',
    
'password' => 'tesstuser',
    
'password2' => 'tesstuser',
    
'first_name' => 'test',
    
'middle_name' => 'test',
    
'last_name' => 'test',
    
'address_1' => 'test',
    
'address_2' => 'test',
    
'zip' => '00977',
    
'city' => 'test',
    
'virtuemart_country_id' => '147',
    
'virtuemart_state_id' => '',
    
'phone_1' => '',
    
'task' => 'saveUser',
    
'address_type' => 'BT',
    
'option' => 'com_virtuemart',
    
'controller' => 'user',
    
'c97da4a4c007f5b1d0a7c1d3b012e179' => '1',
);
$app JFactory::getApplication('site');

// Initialise the application.
$app->initialise();
$vuser = new VirtueMartModelUser(0);
$r $vuser->store($mdata,TRUE);
if(!empty(
$r)){
var_dump($r);
}
?>


Please help me.Give me some ideas.Thanks.

Milbo

First you should not define the defines yourself. Read here http://dev.virtuemart.net/projects/virtuemart/wiki/Developing_a_module_or_plugin_for_VirtueMart_2

start with including and loading the config.

Then just get the model and let the model do the rest for you, for example
$vuser = new VirtueMartModelUser(0); =>$vuser = VmModel::getModel('user')
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/