Jump to content

Accessing member info and bought items of user


VizionDev

Recommended Posts

Posted

Hey,

support/guides/_/ips-community-suite-apps/ip-cont/raw-php-in-ipcontent-r282

This page suggests that when using a Manual PHP block, you have access to memberData. however:

var_dump($this->memberData) // Produces a "Fatal Error"
var_dump($this) // Returns NULL

So I can only assume this documentation is out of date,

Long story short, I'm also using IP.Nexus and need to check if a product has been purchased

 

Can anybody point me in the right direction or maybe to some documentation I missed

Posted

I assume you are using IPS4?

You load via: \IPS\Member::load

 

Hey thanks for your response.

Yes I am using IPv4

Could you by chance please elaborate on what you mean, or point me to the docs because I couldn't find much

Posted
$this->memberData['member_id']//3.x
\IPS\Member::loggedIn()->member_id//4.x

Assuming that you wish to work with the logged in user as $this->memberData was, \IPS\Member::loggedIn() returns an object of \IPS\Member for the currently logged in user, and the properties of said object will hold the data, instead of it being an array. Beyond that it's much the same.

Posted
$this->memberData['member_id']//3.x
\IPS\Member::loggedIn()->member_id//4.x

Assuming that you wish to work with the logged in user as $this->memberData was, \IPS\Member::loggedIn() returns an object of \IPS\Member for the currently logged in user, and the properties of said object will hold the data, instead of it being an array. Beyond that it's much the same.

Ahh clarity.

Thank you very much mate :)

Posted

IPS4 docs are actually on this site, not the main site

https://community.invisionpower.com/4docs/

 

What kind of information is it you want to access?

Nothing for developers though, all I needed to access was the product id's that the loggedIn user had purchased.

Commerce license isn't active, so I can't go digging through the code for your answer, or I would have. My apologies. Please do clarify so others may be able to help. :)

Thanks for the thought :)

For the record I just accessed the database directly given I was unable to find anything for it anywhere.

I created a block with the following:

$IPBSql = new MySQLi('localhost', 'user', 'pass', 'ipb_db');
$MainSql = new MySQLi('localhost', 'user', 'pass', 'my_db');

$MemberID = \IPS\Member::loggedIn()->member_id;
$TimeNow = time();
$Package = false;

$st = $IPBSql->prepare("SELECT ps_name,ps_item_id FROM nexus_purchases WHERE ps_expire > ? AND ps_member = ?");
$st->bind_param('ii', $TimeNow, $MemberID);
$st->bind_result($Name, $ItemID);
$st->execute();

if ($st->fetch()) {
	$st->close();

	switch ($ItemID) {
		case 7: {
			$Package = "Bronze";
			$st = $MainSql->query("SELECT * FROM tblProperties WHERE UNIX_TIMESTAMP() > (Added + (86400*2)) ORDER BY PropertyID DESC");
			$Data = array();
			while ($tmp = $st->fetch_array(MYSQLI_ASSOC)) $Data[] = $tmp;
		}
		break;
		
		case 8: {
			$Package = "Silver";
			$st = $MainSql->query("SELECT * FROM tblProperties WHERE UNIX_TIMESTAMP() > (Added + 86400) ORDER BY PropertyID DESC");
			$Data = array();
			while ($tmp = $st->fetch_array(MYSQLI_ASSOC)) $Data[] = $tmp;
		}
		break;
		
		case 9: {
			$Package = "Gold";
			$st = $MainSql->query("SELECT * FROM tblProperties ORDER BY PropertyID DESC");
			$Data = array();
			while ($tmp = $st->fetch_array(MYSQLI_ASSOC)) $Data[] = $tmp;
		}
		break;
		
		default: {
			$Package = false; 
			$st = $MainSql->query("SELECT * FROM tblProperties WHERE UNIX_TIMESTAMP() > (Added + (86400*7)) ORDER BY PropertyID DESC");
			$Data = array();
			while ($tmp = $st->fetch_array(MYSQLI_ASSOC)) $Data[] = $tmp;
		}
		break;
	}
}
else
{
  $st->close();
}

 

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...