I need to set the shoppergroup for guest users based on a region parameter (that they choose).
I thought that using the following inside a system plugin (onAfterDispatch) would work:
// Getting a registered user and piggy-backing on that.
$user = JFactory::getUser(801);
/** @var TableVmusers $vm_user */
$vm_user_model = new VirtueMartModelUser();
$vm_user = $vm_user_model->getUser();
$vm_user->JUser = $user;
$region = JFactory::$application->input->get('region');
$vm_user->shopper_groups = [0 => $region];
But it doesn't seem to work.
JFactory::$application
will cause an error. Remove the$
beforeapplication
$region
is actually initialised and works, that's not the problem, I'm not sure how to redefine the shopper group so that VM will actually respect it.