Author Topic: Get user data via Joomla user ID  (Read 367 times)

Huubs

  • Jr. Member
  • **
  • Posts: 183
Get user data via Joomla user ID
« on: February 10, 2020, 09:15:50 am »
Hello,

I want to add a userfield with an image path so users can upload logo to their profile. But I'm struggling with how to accomplish this. When the user is logged in I can get the Joomla ID from the user, but how can I then get the Shop user data? So I can get their user data and fill in the correct field I created? Is there some sort of function for it?

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9374
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Get user data via Joomla user ID
« Reply #1 on: February 10, 2020, 11:23:21 am »
$userModel = VmModel::getModel('user');
$userDetails = $userModel->getUser();

should work
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Huubs

  • Jr. Member
  • **
  • Posts: 183
Re: Get user data via Joomla user ID
« Reply #2 on: February 10, 2020, 14:50:45 pm »
Thanks that works. But now how can I set a certain field.

I tried using this:

Code: [Select]
$userModel = VmModel::getModel('user');
$userDetails = $userModel->getUser();

$userDetails->userInfo[1]->imagepath = 'path/to/file.jpg';


But it's not saving the data. is there a function I need to use?

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4168
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Get user data via Joomla user ID
« Reply #3 on: February 10, 2020, 16:18:33 pm »
You should add a field imagepath in the shopperfields
YOURSITE/administrator/index.php?option=com_virtuemart&view=userfields
then you add a script so the user can  upload an image for eg. Or you do a Virtuemart shopperfield plugin (vmuserfield).

Huubs

  • Jr. Member
  • **
  • Posts: 183
Re: Get user data via Joomla user ID
« Reply #4 on: February 10, 2020, 16:31:29 pm »
You should add a field imagepath in the shopperfields
YOURSITE/administrator/index.php?option=com_virtuemart&view=userfields
then you add a script so the user can  upload an image for eg. Or you do a Virtuemart shopperfield plugin (vmuserfield).

I have done that. The field is already there. But when I run the script I see it filled in, but it doesn't save the actual data... So I thought maybe it's protected or something?

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4168
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Get user data via Joomla user ID
« Reply #5 on: February 11, 2020, 17:40:01 pm »
Perhaps you disabled it or the filed name is not right(compare with the other fields name)

Huubs

  • Jr. Member
  • **
  • Posts: 183
Re: Get user data via Joomla user ID
« Reply #6 on: February 13, 2020, 11:56:14 am »
Perhaps you disabled it or the filed name is not right(compare with the other fields name)

Nope haven't disabled it. I just tested if I could change other fields via this method, and that is also not possible. For example first_name isn't changed when I change it via code:

Code: [Select]
<?php

$userModel 
VmModel::getModel('user');
$userDetails $userModel->getUser();

$userData array_keys($userDetails->userInfo);


$userDetails->userInfo[$userData[0]]->imagepath '/images/virtuemart/'.$form->data['file'];

$userDetails->userInfo[$userData[0]]->first_name $form->data['name'];


echo 
"Uploaded logo: <img src='".$userDetails->userInfo[$userData[0]]->imagepath."' 
 style='width:200px; height:auto' /><br />"
// shows the uploaded logo

echo $userDetails->userInfo[$userData[0]]->first_name//shows the input name


?>

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4168
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Get user data via Joomla user ID
« Reply #7 on: February 13, 2020, 13:25:29 pm »
Curious way to set the datas. Perhaps you do it wrong.

Huubs

  • Jr. Member
  • **
  • Posts: 183
Re: Get user data via Joomla user ID
« Reply #8 on: Today at 13:07:52 »
Curious way to set the datas. Perhaps you do it wrong.

What do you mean by this? How can I do it the right way??