How to get the Name and e-mail addres in plugin?

  • Posts: 151
  • Thank you received: 9
11 years 2 months ago #126113

Hi,

I created a plugin and now I need to get the user NAME and EMAIL address to send it via cURL to our external list server.

I have this:

function onAfterOrderUpdate(&$order,&$send_email){
	if(!empty($order->order_id)){
		if($order->order_status == 'confirmed'){ 
			$userClass = hikashop_get('class.user');
			$user = $userClass->get($order->order_user_id);
			$username = $user->username;
			$email = $user->email;

but the variables $username and $email are not filled.

Please help.

Kind regards,
Maurice

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
11 years 2 months ago #126130

Hi,

That should work fine, unless you set the "registration" option of the configuration to "no registration" and in that case, no joomla user account is created for the user and thus the values username and email of $user, which come from the joomla user data, won't be filled.

In such case, if you still want to keep your checkout as a "guest checkout", you should take the email address from user_email which is coming from the hikashop user data.
Regarding the name, HikaShop doesn't store any name in the user data. So either you get it from the main address with a call to the getByUser function of class.address of the user, or you do without.

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

  • Posts: 151
  • Thank you received: 9
11 years 2 months ago #126175

Hi Nicolas,

Our registration is set to simplified registration and Joomla accounts are being created.

So I don't understand why the strings $username and $email are empty???
To test it, I send an e-mail to myself from within this function. When an orderstatus changes to confirmed, the email is sent and received, but both strings are empty...

Could there be anything else going on?

Maurice

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

  • Posts: 26165
  • Thank you received: 4029
  • MODERATOR
11 years 2 months ago #126212

Hi,

For the code I read, I can't answer you, it looks good.
All I can say is that, if you don't have an email or a username, it means that the HikaShop user which is link to the order does not have an username and an email (so it is not link to a Joomla user).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 151
  • Thank you received: 9
11 years 2 months ago #126271

Hi,

When I read what's in $userClass I get this:

hikashopUserClass Object (
[tables] => Array
(
[0] => user
)

[pkeys] => Array
(
[0] => user_id
)

[namekeys] => Array
(
)

[_errors:protected] => Array
(
)

[database] => JDatabaseMySQL Object
(
[name] => mysql
[nameQuote:protected] => `
[nullDate:protected] => 0000-00-00 00:00:00
[dbMinimum:protected] => 5.0.4
[_database:JDatabase:private] => ************
[connection:protected] => Resource id #32
[count:protected] => 0
[cursor:protected] => Resource id #241
[debug:protected] =>
[limit:protected] => 0
[log:protected] => Array
(
)

[offset:protected] => 0
[sql:protected] => SELECT a.*,b.* FROM #__hikashop_user AS a LEFT JOIN #__users AS b ON a.user_cms_id=b.id WHERE a.user_id=0
[tablePrefix:protected] => *****_
[utf:protected] => 1
[errorNum:protected] => 0
[errorMsg:protected] =>
[hasQuoted:protected] =>
[quoted:protected] => Array
(
)

)

)

I'm not sure what this means, but it looks empty. The user is 100% absolutely in the joomla user list and has an e-mail address.
Any other ideas how I can troubleshoot this?

Maurice


P.S.: this is the complete file content:

<?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
class plgHikashopInterspire extends JPlugin
{
	function plgHikashopInterspire(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('hikashop', 'history');
			if(version_compare(JVERSION,'2.5','<')){
				jimport('joomla.html.parameter');
				$this->params = new JParameter($plugin->params);
			} else {
				$this->params = new JRegistry($plugin->params);
			}
		}
	}

	function onAfterOrderCreate(&$order,&$send_email){
		return $this->onAfterOrderUpdate($order,$send_email);
	}

	function onAfterOrderUpdate(&$order,&$send_email){
		if(!empty($order->order_id)){
			if($order->order_status == 'confirmed'){ 
				$userClass = hikashop_get('class.user');
				$user = $userClass->get($order->order_user_id);
				$name = $user->username;
				$mail = $user->email;
				
				// Testing
				$results = print_r($userClass, true);

				// Test e-mail
				$to      = 'mailservice@****.nl';
				$subject = 'A user has been added to the FollowUp list';
				$headers = 'From: info@****.nl' . "\r\n" .
						   'Reply-To: info@****.nl' . "\r\n" .
						   'X-Mailer: PHP/' . phpversion();
						   
				$message .= "Results Array:  $results \r\n" ;
				$message .= "Name:  $name \r\n" ;
				$message .= "Email: $mail" ;

				mail($to, $subject, $message, $headers);
			}

		}
		return true;
	}
}

Last edit: 11 years 2 months ago by Maurice.

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

  • Posts: 26165
  • Thank you received: 4029
  • MODERATOR
11 years 2 months ago #126272

$user no $userClass


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 151
  • Thank you received: 9
11 years 2 months ago #126274

When I do:

$results = print_r($user, true);

$results is empty.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 2 months ago #126316

Hi,

The code seem to be correct, thanks to set the Joomla error reporting to maximum to see if an error is returned.
And thanks to check if the id given in "order_user_id" exist in the database via phpMyAdmin.

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

Time to create page: 0.077 seconds
Powered by Kunena Forum