News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

JUser::_load: Unable to load user with id:

Started by RuBAN, March 22, 2012, 08:21:05 AM

Previous topic - Next topic

RuBAN

Hello! If you try to change the status of orders I give out messages JUser :: _load: Unable to load user with id: N, where N is different each time. The site of two users with id 42 and 44 ..
How can I fix it?
Thanks in advance!


marcodelpercio

Yes RuBAN it's an old annoying bug however regardless its age and proposed fix they've not fixed it yet :-(

Milbo

? Imho this is fixed, maybe I missed a file, where it is missing? and why do you push up a thread already a month old?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

marcodelpercio

It is not fixed, I've just updated to VM stable 2.0.6 and it is still there, please look at the link above.

marcodelpercio

This is a screenshot as proof...regardless of the language the error is clear enough, the same of a month ago.

[attachment cleanup by admin]

Milbo

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

marcodelpercio

It's components/com_virtuemart/views/invoice/view.html.php  Line 213 

Full explanation is here: http://forum.virtuemart.net/index.php?topic=99383.msg336282

Milbo

I just had never this bug I changed the order status in the last days very often. I know the issue itself. But in invoices it is used with parameter and so the model id is not used.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

marcodelpercio

IMHO I trust you however from what I see VM is still confusing order id with user id, that's why I'm still getting the error. As you can see by the screenshot attached before I've fresh update of 2.0.6 stable on Joomla 2.5.4.

I just tried re-applying my workaround and it solves the problem however I'd like to remove hacks from component files.

Milbo


$virtuemart_userinfo_id = $usermodel->getBTuserinfo_id($userId);


is only using the _id of the $usermodel when no id is given.


function getBTuserinfo_id($id = 0){
if(empty($this->_db)) $this->_db = JFactory::getDBO();

if($id == 0){
$id = $this->_id;
vmdebug('getBTuserinfo_id is '.$this->_id);
}

$q = 'SELECT `virtuemart_userinfo_id` FROM `#__virtuemart_userinfos` WHERE `virtuemart_user_id` = "' .(int)$id .'" AND `address_type`="BT" ';
$this->_db->setQuery($q);
return $this->_db->loadResult();
}
[code]

So I do not understand the reason
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

marcodelpercio

Maybe I wasn't  clear enough or you didn't read what I wrote in http://forum.virtuemart.net/index.php?topic=99383.msg336282
The problem is not caused by getBTuserinfo_id rather the JUser::_load error is caused by $usermodel->getUserInfoInUserFields(... under it.
As I have already explained getUserInfoInUserFields is working on a usermodel instance whose id is wrongly set as the order id.

Try the following:
Open Orders view in backend and pick any order to change its state. Pay attention to the order id you're changing and save its changed status. VM will raise an error telling you JUser::_load: Unable to load user with id:X where X is exactly the order id of the order you're changing.

You may also try the following debug code to understand what is happening in VirtueMartModelUser constructor class


class VirtueMartModelUser extends VmModel {

/**
* Constructor for the user model.
*
* The user ID is read and detmimined if it is an array of ids or just one single id.
*/
function __construct(){
           /* DEBUG CODE HERE   START */
           $myFile = "VirtueMartModelUser.log";
           $fh = fopen($myFile, 'w') or die("can't open file");

           $stringData = "VirtueMartModelUser before parent_construct ID IS: " . $this->_id . "\n";
           fwrite($fh, $stringData);
           /* DEBUG CODE HERE   END */

parent::__construct();

           /* DEBUG CODE HERE   START */
           $stringData = "VirtueMartModelUser after parent_construct ID IS: " . $this->_id . "\n";
           fwrite($fh, $stringData);
           fclose($fh);
           /* DEBUG CODE HERE   END */

$this->setMainTable('vmusers');
$this->setToggleName('user_is_vendor');
$this->addvalidOrderingFieldName(array('ju.username','ju.name','sg.virtuemart_shoppergroup_id','shopper_group_name','shopper_group_desc') );
array_unshift($this->_validOrderingFieldName,'ju.id');
// $user = JFactory::getUser();
// $this->_id = $user->id;
}


As I have emphasized in previous post in components/com_virtuemart/views/invoice/view.html.php when $usermodel = VmModel::getModel('user'); gets invoked (in display method) this forces invocation of VirtueMartModelUser costructor which will actually construct the usermodel instance with wrong id. If you check the debug log file VirtueMartModelUser.log you'll notice that the returned VirtueMartModelUser instance will have user id = order id which is wrong and causes the described error.

PRO

I got this when changing my superadmin id.

WHAT i had to do is change the table

   jos_user_usergroup_map

to reflect the new id.


marcodelpercio

I'm not sure what does it matter superadmin id... anyway I proposed a fix looooong time ago http://forum.virtuemart.net/index.php?topic=99383.msg328217 you actually already have the correct user id in the $userId variable exactly one row above...you simply have to set it using setId($userId); on the usermodel instance so that the usermodel instance has the correct id of the user.

I don't know if my suggested fix is the recommended way of doing it however it works, I'd just like to get rid of this error which is "surviving" after 2 stable releases and it is quite a common operation to change an order status. I'd like a hackless VM

PRO

marcodelpercio,

does this happen on a  migrated site that vmart was migrated first, and then Joomla was migrated to 2.5/1.7 ?