News:

Looking for documentation? Take a look on our wiki

Main Menu

Automatically assign shopper group based on Joomla User group

Started by SoTrue, July 13, 2018, 17:32:02 PM

Previous topic - Next topic

SoTrue

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

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

SoTrue

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();



GJC Web Design

$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


GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation