Support

Home Forums Event Espresso Premium Mysql: retrieve name of registrant to show in affliateWP recomendations

Mysql: retrieve name of registrant to show in affliateWP recomendations

Posted: September 5, 2024 at 12:29 pm

Viewing 13 reply threads


Markahn

September 5, 2024 at 12:29 pm

We need to show the EE-registrants name instead of a reference ID in affiliateWP. This refrence ID corresponds uniquely with the search results in EE-transactions as ID (a 5-digit number). Can anyone help me write the mysql-code (and maybe PHP too) I have to use in a php file to retrieve the name of the registrant corresponding to that ID in EE-transactions?


Tony

  • Support Staff

September 5, 2024 at 2:05 pm

Hi there,

This refrence ID corresponds uniquely with the search results in EE-transactions as ID (a 5-digit number).

5 digit number? The Transaction ID’s are an auto incrementing row ID which starts at 1 and grows from there. Having a 5 digit TXN ID is easily doable, I’m just checking the value is indeed the TXN ID here… are you sure it is?

Can anyone help me write the mysql-code (and maybe PHP too) I have to use in a php file to retrieve the name of the registrant corresponding to that ID in EE-transactions?

Generally, we don’t provide any custom code like this.

However, if you have the TXN ID already and just want to pull the Primary registrant from that using our model system (in PHP, NOT directly via SQL) then I can help point you in the right direction for what you need to be looking into if that helps?


Markahn

September 5, 2024 at 2:28 pm

Thanks Tony for your reply. I guess it might indeed the TXN-ID. It is probably 5-digits because our system is already working since years. If I can get the corresponding Primary registrant or the one who is recorded in that specific transaction via php using your model will be fine. I just need to pass the name to another php-function in the affiliate plugin.


Tony

  • Support Staff

September 5, 2024 at 3:02 pm

Querying with the model system takes a LOT of the work out for you tbh.

If you have the TXN ID you can just pull the EE_Transaction object using the models with that ID, like so (I’ll use 11111 as the ID for now):

$txn = EEM_Transaction::instance()->get_one_by_ID(11111);

Now check we have an expert object returned (EE_Transaction) and then pull the primary registrant from it.

if( $txn instanceof EE_transaction ) {
    $primary_reg = $txn->->primary_registration();
    $attendee = $primary_reg->attendee();
}

Now $attendee contains the EE_Contact object for the primary registration, aka the Primary Registant.

Now you have a much of methods on $attendee to pull in details you may want….

$attendee->fname();
$attendee->lname();
$attendee->full_name();

I think all of those a fairly self-explanatory but what I recommend using is Kint:

https://github.com/DuckDivers/kint-debugger

It is a great little tool for debugging, enable that plugin and then do d($attendee); which will give you an output like this:

https://monosnap.com/file/8V3G2oH73FNpUnfyvhE090k813VeCo

The Available Methods tab is very useful for finding methods on a class which may have what you need.

If you are going to be working with EE for custom code I highly recommend reading over the docs on the model system, it makes pulling in pretty much any data within EE relatively easy (much easier than writing your own SQL and joining all of the tables yourself).

See here:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md


Markahn

September 6, 2024 at 9:05 am

Thanks Tony, that´s really helpful!


Markahn

September 6, 2024 at 9:11 am

Ups the last link here doesn´t work: https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md


Markahn

September 6, 2024 at 9:13 am

just saying. Found it here: https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md


Markahn

September 6, 2024 at 9:23 am

ups, also don´t work when clicked…check here:
https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System and click through to model querying


Tony

  • Support Staff

September 6, 2024 at 9:31 am

Hi there,

Its the forums formatting the -- within the link, so the above actually ends up as:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G%E2%80%93Model-System/model-querying.md

The URL you need is:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G--Model-System/model-querying.md


Markahn

September 7, 2024 at 9:42 am

in EE Plugin I found a modul called EED_Affiliate_WP.module.php. Wouldn´t it be much easier to change the code within this modul to just add the name of the attendee?
E.g. here:
/**
* Callback for AHEE__EE_Payment_Processor__update_txn_based_on_payment that is used to create the initial referral record
* if possible.
*
* @param EE_Transaction $transaction
* @param EE_Payment|null $payment
*/
public static function create_referral_record(EE_Transaction $transaction, $payment)
{
$awp = function_exists(‘affiliate_wp’) ? affiliate_wp() : null;
if ($awp instanceof Affiliate_WP
&& ! $awp->referrals->get_by(‘reference’, $transaction->ID(), self::$_context) // don’t create if its already present.
) {
self::_maybe_initiate_affiliate_tracking($transaction, $awp);
}
}

May I ask what I would have to write here to add the attendees name to the TXN_ID which is send over to Affiliate WP?


Markahn

September 7, 2024 at 11:18 am

While $txn instanceof EE_transaction I get an error here that I can not debug:
$primary_reg = $txn->->primary_registration();
//$attendee = $primary_reg->attendee();

What if I do not have a primary registration but only a participant?


Markahn

September 7, 2024 at 12:27 pm

This is what the debugger delivers befor:
‘TXN_reg_steps’ => string(107) “a:3:{s:20:”attendee_information”;b:1;s:15:”payment_options”;i:1724789058;s:21:”f…”

a:3:{s:20:”attendee_information”;b:1;s:15:”payment_options”;i:1724789058;s:21:”finalize_registration”;b:1;}
If I´m searching for primary_registration theres no result.


Markahn

September 7, 2024 at 2:01 pm

meanwhile got this error message to the script snippet above:
Parse error: syntax error, unexpected token “->”, expecting identifier or variable or “{” or “$” in /var/www/vhosts/…


Tony

  • Support Staff

September 8, 2024 at 1:35 pm

Wouldn´t it be much easier to change the code within this modul to just add the name of the attendee?

Sure, it’d be easier to hack up core but then you lost the ability to update that add-on and we can’t provide support for it as it has been modified.

If you want to go down that route you’d be much better creating your own function to ‘unhook’ the default EE function and replace it with your own to add whatever content you want it to be.

May I ask what I would have to write here to add the attendees name to the TXN_ID which is send over to Affiliate WP?

This isn’t custom code we are going to be able to write for you on the forums.

May I ask what I would have to write here to add the attendees name to the TXN_ID which is send over to Affiliate WP?

ADD to the TXN_ID? Previously you wanted to replace it.

The TXN_ID here is a unique referral reference, with replacing it with the attendee name you lost the unique part of that becuase multiple transactions can be linked to the same name…. that could cause tissue later when you want to retrieve the referral.

While $txn instanceof EE_transaction I get an error here that I can not debug:
$primary_reg = $txn->->primary_registration();
//$attendee = $primary_reg->attendee();

$primary_reg = $txn->->primary_registration();

See the ->->, that isn’t valid PHP and will be why your getting the errors you’ve posted, it needs to just be ->.

For this kind of custom development you’ll need to be familiar with PHP and OOP to get this working.

What if I do not have a primary registration but only a participant?

I’m not sure I understand this, that code it requesting the primary registration for a transaction, within EE a traction will always have a primary registration.

This is what the debugger delivers befor:
‘TXN_reg_steps’ => string(107) “a:3:{s:20:”attendee_information”;b:1;s:15:”payment_options”;i:1724789058;s:21:”f…”

a:3:{s:20:”attendee_information”;b:1;s:15:”payment_options”;i:1724789058;s:21:”finalize_registration”;b:1;}
If I´m searching for primary_registration theres no result.

Sorry but without some context here I don’t have any idea what that relates to.

meanwhile got this error message to the script snippet above:
Parse error: syntax error, unexpected token “->”, expecting identifier or variable or “{” or “$” in /var/www/vhosts/…

That’s from the ->-> above, remove that and this error should stop.

Viewing 13 reply threads

You must be logged in to reply to this support post. Sign In or Register for an Account

Event Espresso