Author Topic: VM3.0.18 - Saving edit address removes users groups  (Read 2427 times)

xtech86

  • Beginner
  • *
  • Posts: 17
VM3.0.18 - Saving edit address removes users groups
« 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:
Code: [Select]
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

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10485
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: VM3.0.18 - Saving edit address removes users groups
« Reply #1 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

Code: [Select]
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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/