Jerome wrote: You need to create the user in Joomla first, using the Joomla API/functions.
Then you will be able to use the "save" function of the HikaShop user class, giving him an object with the fields you want to store in the database.
You can check the table "hikashop_user" to know more about the different fields you can save in the database.
Hi Jerome,
Okay, finally I have got pice of code, which is able create user in Joomla from external script called via SOAP. GOOD.
So I have $user_cms_id
I have spend now again about 60 minutes, reading user.php of HikaShop, as well as others.
And may be I am totally stupid, but I cannot understand how to step from Joomla user to instance of HikaShop user.
Let me explain why I have problems here and where my brain is lost. You can read only if you are interested to see this lost-walks. Question itself is at the end.
1) HOW TO CREATE INSTANCE of hikashopUserClass?
1.1) Create instance via new?
1.2) But in many places of HikaShop I see line as:
$userClass = hikashop_get('class.user');
2) HOW TO bind this instance of hikashop user to user_cms_id?
Again I see different places about this, but they are different. For example:
2.1) field.php:
$userClass = hikashop_get('class.user');
$user = $userClass->get($user_id);
$guest = !(bool)@$user->user_cms_id;
2.2) classes/user.php
For me this function looks like perfect factory-convertor cms_id into hikashop user instance.
But you say NO, not for me.
function getID($cms_id,$type='cms'){
$user = $this->get($cms_id,$type);
$id = (int)@$user->user_id;
if(empty($id)&&$type=='cms'){
$userData = JFactory::getUser($cms_id);
if(!empty($userData)){
$user = new stdClass();
$user->user_cms_id = $cms_id;
$user->user_email = $userData->email;
$id = $this->save($user);
}
}
return $id;
}
2.3) classes/user.php
Function SAVE() is absolutely confusing after even 5 times reading. Why? It is enough to look on first lines
function save(&$element,$skipJoomla=false){
$new = true;
if(!empty($element->user_id)){
$new = false;
}else{
if(empty($element->user_created_ip)){
$element->user_created_ip = hikashop_getIP();
}
if(empty($element->user_created)){
$element->user_created = time();
}
if(empty($element->user_email)&&!empty($element->user_cms_id)){
$user = JFactory::getUser($element->user_cms_id);
$element->user_email = $user->email;
}elseif(!empty($element->user_email)&&empty($element->user_cms_id)){
}
}
** IF something is empty it is able to use user_cms_id from $element, which comes as EXTERNAL parameter.
Question comes to mind: Hmmm, may be I should here pass my cmd_id? But what is $element in this case?
** Okay, I try to find call of this save() method, to see what is $element ... and I find such call in the same user.php
function saveForm(){
...
$element = $fieldsClass->getInput('user',$oldUser);
...
$element->user_id = $user_id;
$status = $this->save($element);
...
and
function register(&$checkout,$page='checkout',$redirect=true){
...
$userData = $fieldClass->getInput('user',$old,!@$checkout->cart_update);
...
$this->user_id = $this->save($userData);
...
So here I see that $element in save() in fact is some $userData, which comes from getInput()....
what is this? how to use this? Again Puzzle...
Besides I do not need any Input() ...
==============================================================================
Jerome, this is why without docs and comments in code, just reading CODE, it is far not enough to
GUESS how to use that classes and methods. And be sure, I am very used to quite complex projects.
You see? Will be great to get few more samples, comment over each class and over most important methods which users can use.
I perfectly understand that your product works well, and you can use it, but we must be able also
Okay, finally can you provide that few lines code to give me push forward?
My current state is below.
I need some push to start work with AddUserToHikaShop()
Thank you for any help here
function AddUserToJoomla( $params )
{
$user = new JUser;
// RZ: if you look into code of bind() function, you will see it cares first of all
// about username and passwords, making hash of password also.
// So these 3 params we assign to using via bind(), all rest params via set() methods.
//
$data = array(
'username' => $params->User->login,
'password' => $params->User->password,
'password2'=> $params->User->password,
);
$bind_res = $user->bind($data);
$user->set( 'name' , $params->User->firstname.' '.$params->User->lastname );
$user->set( 'email' , $params->User->email );
$user->set( 'block' , 0 );
$user->set( 'groups' , array("2") );
if( $user->save() )
return $user->id;
else
return false;
}
function AddUserToHikaShop( $params, $cms_user_id )
{
// $userClass = hikashop_get('class.user');
????????????????????????????????????????????????????????????????????????????????
}
//****************************************************************************************
// SOAP entry points:
//****************************************************************************************
// -----------------------------------------
function AddUser($params)
{
// Step 1: Add new user into Joomla
$cms_user_id = AddUserToJoomla( $params );
if( $cms_user_id == false )
return new SoapFault( "AddUserToJoomlaFault", "Cannot create user: " . $params->User->login );
// Step 2: Add new user to HikaShop
$hika_user_id = AddUserToHikaShop( $cms_user_id );