[solved] activation mail & include user fields

  • Posts: 101
  • Thank you received: 12
11 years 5 months ago #106169

Hi,

I'm able to include user and address fields in the email template for "User account" (see code below)
I'd like to show the same information in the mail that the admin gets with the subject of COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT.

This should be the text that shows the name, email and the username and the activation link to approve:
COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY

Hello administrator,\n\nA new user has registered at %s.\nThe user has verified his email, and requests that you approve his account.\nThis email contains their details:\n\n Name : %s \n email: %s \n Username: %s \n\nYou can activate the user by clicking on the link below:\n %s \n


This way the person that gets this email can see all the info and decide whether or not to activate/approve it.

Thanks.

Here is an example of the code for "user account" email template in case someone wants to use it:
<?php echo JText::sprintf('YOU_CAN_LOG_IN_WITH');?><br/>
<?php echo JText::sprintf('HIKA_USERNAME').': '.$data->username;?><br/>
<?php echo JText::sprintf('HIKA_PASSWORD').': '.$data->password;?><br/>
<br/>
<?php echo JText::sprintf('HIKA_EMAIL').': '.$data->email;?><br/>
<?php echo JText::sprintf('COMPANY').': '.$data->user_data->user_company_name;?><br/>
<?php echo JText::sprintf('LINE_OF_BUSINESS').' : '.$data->user_data->user_line_of_business;?><br/>
<?php echo JText::sprintf('VAT_N').': '.$data->user_data->user_vat_nr;?><br/>
<?php echo JText::sprintf('TELEPHONE').': '.$data->user_data->user_work_tel;?><br/>
<?php echo JText::sprintf('FAX').': '.$data->user_data->user_fax;?><br/>
<?php echo JText::sprintf('MOBILE_N').': '.$data->user_data->user_mobile;?><br/>
<?php echo JText::sprintf('LANGUAGE').': '.$data->user_data->user_language;?><br/>
<?php echo JText::sprintf('ALREADY_CLIENT').': '.$data->user_data->user_already_customer;?><br/>
<?php echo JText::sprintf('WISH_NEWSLETTER').': '.$data->user_data->user_wish_newsletter;?><br/>
<?php echo JText::sprintf('OPENING_HOURS').': '.$data->user_data->user_opening_hours;?><br/>
<?php echo JText::sprintf('CLOSING_DAYS').': '.$data->user_data->user_closing_days;?><br/>
<br />
<?php echo JText::sprintf('TITLE').': '.$data->address_data->address_title;?><br/>
<?php echo JText::sprintf('FIRSTNAME').': '.$data->address_data->address_firstname;?><br/>
<?php echo JText::sprintf('LASTNAME').': '.$data->address_data->address_lastname;?><br/>
<?php echo JText::sprintf('STREET').': '.$data->address_data->address_street;?><br/>
<?php echo JText::sprintf('BOX').': '.$data->address_data->address_box;?><br/>
<?php echo JText::sprintf('POST_CODE').': '.$data->address_data->address_post_code;?><br/>
<?php echo JText::sprintf('CITY').': '.$data->address_data->address_city;?><br/>
<?php echo JText::sprintf('TELEPHONE').': '.$data->address_data->address_telephone;?><br/>
<?php echo JText::sprintf('COUNTRY').': '.$data->address_data->address_country;?><br/><br/>

Last edit: 11 years 5 months ago by SG.

Please Log in or Create an account to join the conversation.

  • Posts: 82760
  • Thank you received: 13346
  • MODERATOR
11 years 5 months ago #106242

You can edit the "user account admin notification" email of Hikashop in a similar manner for that.

Please Log in or Create an account to join the conversation.

  • Posts: 101
  • Thank you received: 12
11 years 5 months ago #106246

Hi,

That would be great if it is possible like you suggest.
I just don't see this email template. I'm using hikashop 2.1.0 for the moment.
Is this the reason why it isn't there?



Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 82760
  • Thank you received: 13346
  • MODERATOR
11 years 5 months ago #106249

It has been added only in newer versions of HikaShop.
So that's normal.
If you don't see it, it means that HikaShop is not sending any admin notification after HikaShop user registration so there is nothing to edit...

Please Log in or Create an account to join the conversation.

  • Posts: 101
  • Thank you received: 12
11 years 5 months ago #106302

Hi,

I installed the latest hikashop and now I see USER_ACCOUNT_ADMIN_NOTIFICATION in the email template.
1) for some reason it doesn't show the name 'User account admin notification" but USER_ACCOUNT_ADMIN_NOTIFICATION.

2) Inside this file I added one more field ($data->user_data->user_company_name) just to test with it:

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.1.3
 * @author	hikashop.com
 * @copyright	(C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php 
echo JText::sprintf(
	'HIKA_USER_ACCOUNT_ADMIN_NOTIFICATION_BODY',
	$data->name,
	$data->username,
	$data->user_data->user_company_name,
	HIKASHOP_LIVE
);
?>

And in COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY I just added Company: %s
Hello administrator,\n\nA new user has registered at %s.\nThe user has verified his email, and requests that you approve his account.\n
This email contains their details:\n\n  Name :  %s \n  Email:  %s \n Username:  %s \n  Company:  %s \n\nYou can activate the user by clicking on the link below:\n %s \n

When I did these changes I get the following error when I click on the activation link:
Warning: sprintf() [function.sprintf]: Too few arguments in /public_html/site/libraries/joomla/methods.php on line 320

When I remove the last %s it works but I really want to show the other field(s) so the admin has all the info about the user in the mail and approve straight away.

I'm probable missing something. Maybe there is another file that needs to be altered?

Thanks.

Last edit: 11 years 5 months ago by SG.

Please Log in or Create an account to join the conversation.

  • Posts: 82760
  • Thank you received: 13346
  • MODERATOR
11 years 5 months ago #106305

As you can see in the email code, it is that string that you need to change in the translation:
HIKA_USER_ACCOUNT_ADMIN_NOTIFICATION_BODY

Please Log in or Create an account to join the conversation.

  • Posts: 101
  • Thank you received: 12
11 years 5 months ago #106316

Hi Nicolas,

I'm probably confused cause I'm starting to think that I'm not working in the correct place.

Let me start over.

New user registers on the site. The user get's an email to activate it (subject: Account details for %s at %s)
When the user clicks on the link then a mail is send to the administrator to approve (Registration approval required for account of %s at %s)

It's this mail that the administrator receives that should contain the user and address fields.

This is the string:
COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY
So when I add for example the company name it becomes:

Hello administrator,\n\nA new user has registered at %s.\nThe user has verified his email, and requests that you approve his account.\n
This email contains their details:\n\n 
Name : %s \n 
Email: %s \n 
Username: %s \n
Company: %s \n\n
You can activate the user by clicking on the link below:\n %s \n

So something is feeding this string and I first thought it was the email template USER_ACCOUNT_ADMIN_NOTIFICATION
But like you said in the last post it has string HIKA_USER_ACCOUNT_ADMIN_NOTIFICATION_BODY
echo JText::sprintf(
	'HIKA_USER_ACCOUNT_ADMIN_NOTIFICATION_BODY',
	$data->name,
	$data->username,
	HIKASHOP_LIVE
);

So I can only conclude that this is not the right place to add the field(s) since HIKA_USER_ACCOUNT_ADMIN_NOTIFICATION_BODY is not USER_ACCOUNT_ADMIN_NOTIFICATION. I'm looking for the place where COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY is send with the parameters.

After the upgrade from 2.1.0 to 2.1.3 these are the email templates that I see: (only one is added: USER_ACCOUNT_ADMIN_NOTIFICATION)


Thanks for your patience.

Last edit: 11 years 5 months ago by SG.

Please Log in or Create an account to join the conversation.

  • Posts: 82760
  • Thank you received: 13346
  • MODERATOR
11 years 5 months ago #106344

The user account admin activation email is not handled by HikaShop but by joomla. I would recommend to ask that on forum.joomla.org
They should be able to help you on that better than us on how to properly modify it.
If you search through the joomla code, you will find that COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY is in the file components/com_users/models/registration.php so I encourage you to look there.
Unfortunately, you won't be able to easily get the user information in that email as it is not a HikaShop email and thus the data of the user added by HikaShop won't be there either. You would have to load it yourself with MySQL queries to the database before being able to add it to the email text.

Please Log in or Create an account to join the conversation.

  • Posts: 101
  • Thank you received: 12
11 years 5 months ago #106492

Hi,

I did what you suggested and I altered registration.php and I've used the following code;

$db->setQuery(
               'SELECT * FROM '.$db->quoteName('#__hikashop_user').' as a JOIN '.$db->quoteName('#__hikashop_address').' as b '
               .'WHERE a.user_id = b.address_user_id AND '.$db->quoteName('user_cms_id').' = '.$userId
          );
		
		$userInfo = $db->loadObject();

And
$emailBody = JText::sprintf(
		'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY',
		$data['sitename'],
		$data['name'],
		$data['email'],
		$data['username'],
		$userInfo->user_company_name,
		$userInfo->user_line_of_business,
                $userInfo->user_vat_nr,
                $userInfo->user_work_tel,
                $userInfo->user_fax,
                $userInfo->user_mobile,
                $userInfo->user_language,
                $userInfo->user_already_customer,
                $userInfo->user_wish_newsletter,
                $userInfo->user_opening_hours,
		$userInfo->user_closing_days,
		$userInfo->address_title,
                $userInfo->address_firstname,
                $userInfo->address_lastname,
                $userInfo->address_street,
                $userInfo->address_box,
                $userInfo->address_post_code,
                $userInfo->address_city,
                $userInfo->address_telephone,
                $userInfo->address_country,
		$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation']
	);

It seems to work.
If you have any suggestion then please feel free to make correction/modification to the code above.

Too bad there wasn't an email template available to begin with.
If you guys are willing to put this on the todo-list that would be great and we won't need to hack the joomla files.
I know it's not a priority so even if it gets done later that would be better than nothing.

Thanks for pointing me in the right direction.

Greets

Please Log in or Create an account to join the conversation.

  • Posts: 82760
  • Thank you received: 13346
  • MODERATOR
11 years 5 months ago #106524

The problem is that this is an email of Joomla. We cannot provide a template for it as it is joomla which handles it.

I would recommend you to use a class override plugin as explained here my.safaribooksonline.com/book/web-develo...plugins/ch05lev1sec8 in order to avoid modifying the joomla core file.

The following user(s) said Thank You: SG

Please Log in or Create an account to join the conversation.

  • Posts: 101
  • Thank you received: 12
11 years 5 months ago #106529

Hi Nicolas,

Thank you so much for the information. I will definitely take a look.
I really appreciate it!!!!!

Please Log in or Create an account to join the conversation.

Time to create page: 0.074 seconds
Powered by Kunena Forum