• Fabrik4.5.3 for J!5.3.0 and J!4.2+is out

    You must update from Fabrik4.5.1 if you are running Joomla!5.3.0

    See Announcements

Fixed getting row values in list email plugin

This could just be a persistent brain fart on my part, but...

I have a table called invoices. The table includes a databasejoin element to the members table. From the invoices list, I want to use a list email plugin to email the invoice to the member. So, do I need to make an eval query to select the members.email field? Or is there some way of using placeholders like {invoices___member___email} or maybe {invoices___member}.email?
 
Well, since I think the answer is "no, there is dereferencing like that available", I've moved on to try do it using an eval, but I can't seem to find anything that works. When I hardcode an id, this query works:
Code:
$db = JFactory::getDbo();
$query = $db->getQuery(true);

// Get the member ID from the current row
$memberId = '13635';

$query->select($db->quoteName('email'))
      ->from($db->quoteName('members'))
      ->where($db->quoteName('id') . ' = ' . $memberId);

$db->setQuery($query);
$email = $db->loadResult();

return $email;

But when I try to reference the invoices.member value, no matter how I try, I don't seem to be able to. . Here are some things I tried:

$memberId = (int)$row->invoices___member_raw;
$memberId = (int)$row->invoices___member;
$memberId = (int)$row->['member'];
$memberId = '{invoices___member_raw}';
$memberId = (int)'{invoices___member_raw}';
$memberId = (int)'{invoices___member}';
$memberId = (int){invoices___member_raw};
$memberId = (int)$data['invoices___member'];
$memberId = {invoices___member_raw};
$memberId= '{invoices___member}';
$memberId = '{$thistable}.{email}';
$memberId = {$thistable}.email;
$memberId = '{$thistable___email}';
$memberId = (int)$data['invoices___member'];
$memberId = (int)'{thistable}.member_raw';

I also ran some tests where I tried to put the value of $row into an error message, but it comes out as undefined.

What's the secret sauce? I guess I could create a calc element and store the email there, but I didn't want the extra processing and some work happens outside of fabrik so then i've gotta worry about whether calc has been updated.
 
Last edited:
It says "Row data is in the $row object, like $row->mytable___fk_val" in the php eval helper text on the send email form, but I can't seem get anything but Null when I put $row into an error message or try to do a var_dump using a php list plugin.
 
Thanks I will give that a try. I was also using the list php plugin for some testing and didn’t get a $row value there either so perhaps another tweak is required?
 
Okay, after making the fix, this php worked:

PHP:
use Joomla\CMS\Factory;
// Get the database object
$db = Factory::getDbo();
// Get the member ID from the invoices field
$memberId = $row->invoices___member_raw;
$query = $db->getQuery(true)
            ->select($db->quoteName('email'))
            ->from($db->quoteName('members'))
            ->where($db->quoteName('id') . ' = ' . (int)$memberId);
$db->setQuery($query);
$email = $db->loadResult(); // Get the email address

if ($email) {
    return $email;
} else {
    return null;
}

I hope I've used the most modern standard for the query. I notice that bindings don't work in this instance, fwiw.

Thanks for coming to my rescue!
 

Members online

No members online now.
Back
Top