3

I have added a field in 'Manage User Fields' & when an email is sent to the administrator notifying them of the new user registration, I want to include this new field.

I have written some code to get this new field from #__vm_user_info in /administrator/components/com_virtuemart/classes/ps_shopper.php, in the _sendMail function, as well as added the variable to $message2.

ASEND_MSG has been modified to accept the parameter, but the field is not included in the email to the admin when a user is created. When I go look in the table, the data is there. So to trouble shoot, I hard coded a user name in the select statement, added another user & the correct value was sent for the hard coded user, not the one just added. I am now thinking that it is a commit issue with MySQL, so I put a sleep(4) in the code before I attempt to get the value...no luck.

Can anyone shine some light on this for me??

LarryR....

larryr
  • 1,536
  • 3
  • 17
  • 27

1 Answers1

1
  1. administrator/components/com_virtuemart/classses/ps_shopper.php

Need to add with the following code in function add() before "return true" line :

/**************************** ***********************/ $pwd = $_POST['password'];

            $db = JFactory::getDBO();

        $query = "SELECT id, name, email, username"

        . "\n FROM #__users"

        . "\n ORDER by id DESC LIMIT 1"

        ;

        $db->setQuery( $query );

        $rows = $db->loadObjectList();

        $namee = $rows[0]->name;

        $emaill = $rows[0]->email;

        $usern = $rows[0]->username;

        $pwd;

        $lid = $rows[0]->id;

        $dbv = new ps_DB;

            echo $query = "SELECT *"

        . "\n FROM #__{vm}_user_info"

        . "\n WHERE user_id=$lid"

        ;

        $dbv->setQuery( $query );

        $fid = $db->loadObjectList();



     $field = $fid[0]->extra_field_1;

    $user       = clone(JFactory::getUser());

    $usersConfig = &JComponentHelper::getParams( 'com_users' );

    if ($usersConfig->get('allowUserRegistration') == '0') {

        JError::raiseError( 403, JText::_( 'Access Forbidden' ));

        return false;

    }

    // If user activation is turned on, we need to set the activation information

    $useractivation = $usersConfig->get( 'useractivation' );

    if ($useractivation == '1') 

    {

        jimport('joomla.user.helper');

        $user->set('activation', md5( JUserHelper::genRandomPassword()) );

        $user->set('block', '1');

    }

    $component = 'com_user';

    $activation_link = $mosConfig_live_site."/index.php?option=$component&task=activate&activation=".$user->get('activation');



    $this->_sendMail( $namee , $emaill, $usern, $pwd, $activation_link);

    /************************************************** Spinz ********************************************/

Note : Here we created the mail function for username and password to users mail.

  1. administrator/components/com_virtuemart/classses/ps_shopper.php

Need to comment the line in function register_save() before "return true" line:

    // Send the registration email

//$this->_sendMail( $name, $email, $username, $password, $activation_link );

Note: Here the mail function generated we need to comment that mail functions and create another mail function in add() function of ps_shopper.php in first point.

  1. administrator/components/com_virtuemart/classses/ps_shopper.php

Need to get the extra added field (extra_field_1) in jos_vm_user_info table in the function _sendmail() with following code and that field sent through the mail to user.

    /****************************************************************/


     $db = JFactory::getDBO();

        $query = "SELECT id, name, email, username"

        . "\n FROM #__users"

        . "\n ORDER by id DESC LIMIT 1"

        ;

        $db->setQuery( $query );

        $rows = $db->loadObjectList();

        $lid = $rows[0]->id;

        $dbv = new ps_DB;

        $query = "SELECT *"

        . "\n FROM #__{vm}_user_info"

        . "\n WHERE user_id=$lid"

        ;

        $dbv->setQuery( $query );

        $fid = $db->loadObjectList();



     $field = $fid[0]->extra_field_1;



    $subject    = sprintf ($VM_LANG->_('SEND_SUB',false), $name, $mosConfig_sitename);

    $subject    = vmHtmlEntityDecode($subject, ENT_QUOTES);

    if ($mosConfig_useractivation=="1"){

        $message = sprintf ($VM_LANG->_('USEND_MSG_ACTIVATE',false), $name, $mosConfig_sitename, $activation_link, $mosConfig_live_site, $username, $pwd, $field );

    } else {

        $message = sprintf ($VM_LANG->_('PHPSHOP_USER_SEND_REGISTRATION_DETAILS',false), $name, $mosConfig_sitename, $mosConfig_live_site, $username, $pwd, $field);

    }

/*************************************/

Note :

  1. Initialize the variable "$field" get the extra added field value using query. Then that the extra field value is assigned by message section of the mail.(initialize variable $field having the a value added extra fields in virtuemart).

  2. administrator/components/com_virtuemart/languages/common/english

replace the messages for the following code:

  1. 'USEND_MSG_ACTIVATE' => 'Hello %s,

Thank you for registering at %s. Your account is created and must be activated before you can use it. To activate the account click on the following link or copy-paste it in your browser: %s

After activation you may login to %s using the following username and password:

Username - %s Password - %s Degree - %s'

2.'PHPSHOP_USER_SEND_REGISTRATION_DETAILS' => 'Hello %s,

Thank you for registering at %s. Your customer account has been created. You may login to %s using the following username and password:

Username - %s Password - %s Degree - %s ' Note:

  1. The extra added values assigned by the string %s in language file.

  2. The message having the string values of extra added field value in virtuemart.

  3. The degree shows the added extra field

dineshbabu
  • 11
  • 1