Jump to content

Community

Accessing member info and bought items of user


VizionDev
 Share

Recommended Posts

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

Edited by BlinkGC
Link to comment
Share on other sites

$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.

Edited by Marcher Technologies
Link to comment
Share on other sites

$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 :)

Link to comment
Share on other sites

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();
}

 

 

Edited by BlinkGC
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We use technologies, such as cookies, to customise content and advertising, to provide social media features and to analyse traffic to the site. We also share information about your use of our site with our trusted social media, advertising and analytics partners. See more about cookies and our Privacy Policy