VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: xtech86 on January 12, 2017, 15:43:56 PM

Title: VM3.0.18 - Saving edit address removes users groups
Post by: xtech86 on January 12, 2017, 15:43:56 PM
Hello,

In VM 3.0.18 when you are logged in as an  super user for example and edit the billing address in the frontend VM runs the model file:
/administrator/components/com_virtuemart/models/user.php

And in turn on line 160 you set the shopper groups to a plain array which then causes VM to set the default shopper group see:

if(empty($this->_data->shopper_groups)) $this->_data->shopper_groups = array();


VM needs to be doing a check that this is not the billing or ship to address layout before touching the users shopper groups. As our user then has to login and set the shopper group for the next order they place.

Many thanks
Tony
Title: Re: VM3.0.18 - Saving edit address removes users groups
Post by: Milbo on January 12, 2017, 20:51:39 PM
I think the problem is not in user load, it is in the store function, line 558


if(vmAccess::manager('user.edit')){

$shoppergroupmodel = VmModel::getModel('ShopperGroup');
if(empty($this->_defaultShopperGroup)){
$this->_defaultShopperGroup = $shoppergroupmodel->getDefault(0);
}

if(empty($data['virtuemart_shoppergroup_id']) or $data['virtuemart_shoppergroup_id']==$this->_defaultShopperGroup->virtuemart_shoppergroup_id){
$data['virtuemart_shoppergroup_id'] = array();
}

//We can't do that here, because it deletes the shoppergroup of users with "user.edit" permissions when they checkout
/*if(!isset($data['virtuemart_shoppergroup_id'])){
$data['virtuemart_shoppergroup_id'] = array();
}*/
$shoppergroupData = array('virtuemart_user_id'=>$this->_id,'virtuemart_shoppergroup_id'=>$data['virtuemart_shoppergroup_id']);
$user_shoppergroups_table = $this->getTable('vmuser_shoppergroups');
$res = $user_shoppergroups_table -> bindChecknStore($shoppergroupData);
if(!$res){
vmError('Set shoppergroup error');
$noError = false;
}

}


The reason is that a manager usually sents this data automatically. So we just need to add here that the data is loaded before like already done for the user_is_vendor