Author Topic: How to create VM_USER in Joomla com_user registration  (Read 4311 times)

bart198x

  • Beginner
  • *
  • Posts: 29
How to create VM_USER in Joomla com_user registration
« on: February 28, 2015, 13:24:03 pm »
Hello.
I'm on joomla 2.5.27 and vm 2.6.16.
I've create a plugin for joomla  (extending com_users ) wchich make some things with userfields, anyway..
I try now to extend that plugin with posibility of creating VM_USER and VM_USER_INFOS on 'onUserAfterSave'
The code for that function:
Code: [Select]
public function onUserAfterSave($isnew){
$user = JFactory::getUser();
//$groups = $user->groups;  koment poniewa┼╝ i tak tego nie u┼╝ywam

//Writing newly created user id to my plugin table

if($this->userid == 0){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query ->update($db->quoteName('#__registrationtermscheck'))
->set($db->quoteName('userid') . "=" . $db->quote($isnew['id']))
->where($db->quoteName('username') . "=" . $db->quote($isnew['username']));
$db->setQuery($query);
$result = $db->execute();
}

// Check for component - but if not installed it will throw JError::raiseWarning (info with loading component error )
if (JComponentHelper::getComponent('com_virtuemart', true)->enabled)
{
//here would be creation of empty VM_USER  and USER_INFOS but with necessary fields as ID's etc.
//how to trigger new VM_USER  and USER_INFOS creation having ID of newly created user ??

exit; // that's for tests
}
}


My question actualy is inserted in that code as coment :)
How to trigger new VM_USER  and USER_INFOS creation having ID of newly created joomla user ??
I'm am studying VM code but I can't even found where the new vm_user is creating, how the customer number is creating etc...
I can make it inserting record into DB creating a record 'of the hand' but I want to make it more 'cleanly' (not so brutally :) ).

Of course I want to create vm_user without any adress information (first, last name etc...)just new record with necessary ids, customer number, addres type, and default shopper group, maybe some other datas are necessary too... (I will check maybe in the evening).

Thanks in advance for any suggestions.

bart198x

  • Beginner
  • *
  • Posts: 29
Re: How to create VM_USER in Joomla com_user registration
« Reply #1 on: February 28, 2015, 21:16:15 pm »
Ok thanks for replies :)
The answer code is... Hm I dodn't know...
Eeee:
Code: [Select]
public function onUserAfterSave($isnew){
$user = JFactory::getUser();
$get = JRequest::get();

//Writing newly created user id to my plugin table
if($this->userid == 0){

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query ->update($db->quoteName('#__registrationtermscheck'))
->set($db->quoteName('userid') . "=" . $db->quote($isnew['id']))
->where($db->quoteName('username') . "=" . $db->quote($isnew['username']));
$db->setQuery($query); //for !Joomla 2.5.x
$db->execute(); // for !Joomla 3.x probably :)


// here we start creating virtuemart user having information from com_users including this plugin and datas from it
if (JComponentHelper::getComponent('com_virtuemart', true)->enabled)  //if component is not loaded we will get error info
{
$regVmUser = new stdClass();  //new object to be loaded to db
$regVmuser->virtuemart_user_id = $isnew['id'];
$regVmuser->created_by = $isnew['id'];
$regVmuser->modified_by = $isnew['id'];
$db->insertObject('#__virtuemart_vmusers', $regVmuser); //in this place because later we will add some other things to object


//set object with checkbox values from field params
for($i=1;$i<=5;$i++){
$fieldName = $this->params->get('vmbox'.$i);
$fieldStatusValue = $this->params->get('status'.$i);
if ($fieldName !== 'NULL'){
if ($fieldStatusValue == 1) $value = 1;
elseif ($fieldStatusValue == 2) $value = 0;
$regVmuser->{$fieldName} = $value;
}
}
$regVmuser->address_type = 'BT';     // now we are adding some other fields to object for another table
$regVmuser->name = $isnew['username'];
$db->insertObject('#__virtuemart_userinfos', $regVmuser); //END point... insert last necessary datas
}
}
}

And it works.

Thanks.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10040
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: How to create VM_USER in Joomla com_user registration
« Reply #2 on: March 01, 2015, 10:51:42 am »
Why you just not use directly the VM object?

$umodel = VmModel::getModel('user');
$umodel->store($formdata);

?
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bart198x

  • Beginner
  • *
  • Posts: 29
Re: How to create VM_USER in Joomla com_user registration
« Reply #3 on: March 01, 2015, 19:34:05 pm »
Hi.
Because I was looking for it and I didn't found :)
Thanks :)
As I wrote before that was a dirty method :)

I will check it, but there is a little problem I think. On Joomla registration form I have some custome fields created by my own plugin, and they are not stored in joomla user table (but in my plugin table), but they are displayed (actualy 'updated' from that table) to virtuemart user edit form.
But apart from the fact I can still grab that data from plugin table and put it to model coresponding fields hmm. That might make sense.

Any way I will check that.
Thanks again.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10040
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: How to create VM_USER in Joomla com_user registration
« Reply #4 on: March 02, 2015, 09:47:03 am »
Create a userfield plugin for that.

In general, there is the idea since 4 years to create a joomla user registration plugin for VirtueMart, so that we could use the joomla registration page for vm
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bart198x

  • Beginner
  • *
  • Posts: 29
Re: How to create VM_USER in Joomla com_user registration
« Reply #5 on: March 02, 2015, 10:42:09 am »
So I make it but in simple rule of thumb :)
Realy... There is nothing to loud :) It works on coresponding userfields - (checkbox only - because that was what I need)
Plugin generate 5 checkboxes (if wee need there can  be less - just select not use) should be installed after virtuemart userfields checkbox are created. After that (in plugin config) you can choose coresponding checkbox within plugin and vm (or you can use them as stand alone - they are stored in plugin table)
That was the plan because I didn't like checkbox validation from VM :) (I don't know, but the user can make order even if they are not checked, of cousre there is info that fields are not checked but the order is done? why. The same in registration. Never mind) I just don't know what about security of that. I'm quit lame in joomla and vm programing so plugin is realy 'dirty' and simple... But works, but may be unsecure, and for that I think to give it to my friend to check.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10040
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: How to create VM_USER in Joomla com_user registration
« Reply #6 on: March 02, 2015, 10:50:20 am »
if you can checkout even a check is not set, then it seems your userfield is missing the attribute "required".
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bart198x

  • Beginner
  • *
  • Posts: 29
Re: How to create VM_USER in Joomla com_user registration
« Reply #7 on: March 02, 2015, 11:00:57 am »
Required is checked - but I wil check on. But as I remember I have a problem with that for about year or better that's why I took myself and wrote that plugin (as I remember there was some other things by which I preferred joomla registration instead of vm).
I have to clean that code from var_dumps, comments etc... and check it, and maybe tomorow I will put it somewere just as a curiosity :)
But for now I go back to making signboards (JOB).

I've check that (it is required) don't know why in my case on vm registration form if I don't check checkbox (required - one of two - both required) I get info about missing value, but the vmuser entry is created (userinfos doesn't), if then I check that missing field and hit register again than registration is not to be done (and get no info about finishing registration or missing fields).
On the other hand if I make all field filled in proper way (as they should be for the first time), registration is completed and I get confirmation e-mail with activation link which work properly too. Hmm...  I think that was the reason. When I will have time (in the evening maybe) I will create video to show that (I have removed all overrides to check that - only on core files) :)
Of course we are talking about checkboxs only, other fields work properly.
Test on chrome and FF but on localhost (But I don't believe in other effect on external server)

bart198x

  • Beginner
  • *
  • Posts: 29
Re: How to create VM_USER in Joomla com_user registration
« Reply #8 on: March 02, 2015, 20:02:07 pm »
I don't know what to say...
I made fully clean install and it seems to work.  F... ..
I have to check what I made wrong.
I will write if I get that.


Ok so i see a lot has changed from past  time :) I didn't even knew that there is attachment option haha. Niece