VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: SoTrue on July 13, 2018, 17:32:02 PM

Title: Automatically assign shopper group based on Joomla User group
Post by: SoTrue on July 13, 2018, 17:32:02 PM
Hi Guys,

We use a custom registration form to allow shoppers to register as Wholesalers, once registered this puts the user in the Joomla User Group 'Wholesale', but assigns the user to the shopper group "default shopper'. Is there a way so that all users in the Joomla user group 'Wholesale' automatically get assigned to the Virtuemart shopper group 'Wholesale'?

Regards
D
Title: Re: Automatically assign shopper group based on Joomla User group
Post by: GJC Web Design on July 13, 2018, 19:46:43 PM
https://extensions.joomla.org/extension/bit-change-shopper-group-for-virtuemart/

https://extensions.joomla.org/extension/shopper-group-changer-for-virtuemart/
Title: Re: Automatically assign shopper group based on Joomla User group
Post by: SoTrue on July 24, 2018, 18:51:13 PM
Thank you, but these do not seem to solve the problem as we use a custom registration form which then adds a user to a Joomla User group and sets the shopper group as default. What we would like is for the group to automatically be assigned to Wholesale if the User group is Wholesale.

I have found a code snippet but cannot seem to understand how it works:



$virtuemart_user_id = (int)$formModel->_formData['mytable___userid'];
$address_type = "BT";
$name = $formModel->_formData['mytable___nombre'];
$last_name = $formModel->_formData['mytable___apellido_paterno'];
$first_name = $formModel->_formData['mytable___nombre'];
$middle_name = $formModel->_formData['mytable___apellido_materno'];
$phone_1 = $formModel->_formData['mytable___Telfono_casa'];
$address_1 = $formModel->_formData['mytable___Calle'];
$address_2 = $formModel->_formData['mytable___colonia'];
$city = $formModel->_formData['mytable___Ciudad'];
$virtuemart_state_id = (int)$formModel->_formData['mytable___estado_id'][ 0 ];
$virtuemart_country_id = 138;
$zip = $formModel->_formData['mytable___Codigo_Postal'];

$db =& JFactory::getDBO(); 
$virtuemart_user_id = $db->Quote($virtuemart_user_id);
$address_type =$db->Quote($address_type);
$name = $db->Quote($name);
$last_name = $db->Quote($last_name);
$first_name = $db->Quote($first_name);
$middle_name = $db->Quote($middle_name);
$phone_1 = $db->Quote($phone_1);
$address_1 = $db->Quote($address_1);
$address_2 = $db->Quote($address_2);
$city = $db->Quote($city);
$virtuemart_state_id = $db->Quote($virtuemart_state_id);
$virtuemart_country_id = $db->Quote($virtuemart_country_id);
$zip = $db->Quote($zip);


$db->setQuery("INSERT INTO ultgj_virtuemart_userinfos(virtuemart_user_id,address_type,name,last_name,first_name,middle_name,phone_1,address_1,address_2,city,virtuemart_state_id,virtuemart_country_id,zip) VALUES ($virtuemart_user_id,$address_type,$name,$last_name,$first_name,$middle_name,$phone_1,$address_1,$address_2,$city,$virtuemart_state_id,$virtuemart_country_id,$zip)"); 
$db->query();

$virtuemart_user_id = (int)$formModel->_formData['mytable___userid'];
$customer_number = md5($formModel->_formData['mytable___Usuario']);
$perms = "shopper";

$db =& JFactory::getDBO(); 
$virtuemart_user_id = $db->Quote($virtuemart_user_id);
$customer_number =$db->Quote($customer_number);
$perms = $db->Quote($perms);

$db->setQuery("INSERT INTO ultgj_virtuemart_vmusers (virtuemart_user_id,customer_number,perms) VALUES ($virtuemart_user_id,$customer_number,$perms)"); 
$db->query();


Title: Re: Automatically assign shopper group based on Joomla User group
Post by: GJC Web Design on July 24, 2018, 22:48:08 PM
$db->setQuery("INSERT INTO ultgj_virtuemart_vmusers (virtuemart_user_id,customer_number,perms) VALUES ($virtuemart_user_id,$customer_number,$perms)"); 


Standard VM3 #___virtuemart_vmusers doesn't have a column 'perms'

shopper groups are recorded in #__virtuemart_vmuser_shoppergroups`

is this VM2 or something?

You need to go further back in the code

$perms = Shopper

if joomla grp == Wholesale then $perms = Wholesale