VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: alexanderflr on September 27, 2017, 14:57:29 PM

Title: Don't activate user and don't send e-mail if userfield is checked
Post by: alexanderflr on September 27, 2017, 14:57:29 PM
Hi,
This modification gave me a lot of headaches so I will much appreciate if someone can help me.

I want to create a shopper field (checkbox, lets name it "Don't activate me and don't send me email) that will be displayed in the registration form and
if the user check this when creates a new account, will not be activated so he will need to wait until one administrator activate him.

Thank you,
Title: Re: Don't activate user and don't send e-mail if userfield is checked
Post by: GJC Web Design on September 28, 2017, 11:13:18 AM
as your wanting to alter Joomla config settings not really a VM question

I would guess a user plugin and either onUserAfterSave($user, $isnew, $success, $msg) or onUserBeforeSave($user, $isnew, $success, $msg)
Title: Re: Don't activate user and don't send e-mail if userfield is checked
Post by: alexanderflr on October 02, 2017, 10:59:43 AM
Hi,

Thank you for your reply. I've seen this can be also done through VM shopper edit.

Basically what I would like to do is when a user register to virtuemart and check a userfield (checkbox) to be blocked or not activated.

or... what will also help me is:

if ($shoppergroup == 37113756 ) {
    block user code;

Thank you,

Title: Re: Don't activate user and don't send e-mail if userfield is checked
Post by: GJC Web Design on October 02, 2017, 14:57:36 PM
if u don't want to build a plugin you need to hack

somewhere in public function store(&$data){   in the  user.php model
Title: Re: Don't activate user and don't send e-mail if userfield is checked
Post by: alexanderflr on October 02, 2017, 17:45:12 PM
Hi,

I manage to solve this but by shoppergroup because I don't know how to get or echo values from shopper fields...
Anyway it does exactly what I needed. Here is the code:


<?php

// Get user id and shoppergroup
$user =& JFactory::getUser();
$userId $user->get('id');
$db JFactory::getDbo();
$query 'SELECT `virtuemart_shoppergroup_id` ' ' FROM `#__virtuemart_vmuser_shoppergroups` ' ' WHERE `virtuemart_user_id` =' $userId;
$db->setQuery($query);
$shoppergroup $db->loadResult(); 

// Disable user if shoppergroup =
if ($shoppergroup == 1221746709 ) {

$database =& JFactory::getDBO();
$sql "UPDATE `rk21a_users` SET `block` = '1' WHERE `rk21a_users`.`id` = $userId";
$database->setQuery($sql);
$database->query();

// Sign out the user
$app JFactory::getApplication();              
$user JFactory::getUser();
$user_id $user->get('id');            
$app->logout($user_id, array());

// Display a message for user
echo '<div class="alert alert-notice">';
 echo vmText::('not good');
 echo '</div>';
} else   

?>