I've run into a bug that I can't seem to figure out with a snippet I've been writing. The snippet pulls products from two different database tables and displays them when the user does a search. I have a counter on the page that shows the number of results. Everything is working fine, except that counter. Under most circumstances it shows the correct number, but when there are only results from database #2, the placeholder doesn't pass on any value at all to the chunk.
Here is the code related to counter:
$totalc = $modx->getCount('BbProducts',$c);
$totalc2 = $modx->getCount('BbStyles',$c2);
$total = $totalc + $totalc2;
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
$modx->setPlaceholder($totalVar,$total);
This is fairly straightforward, getting the counts from the two queries I have, adding them together, and creating a placeholder. Here is the problem:
- When $totalc and $totalc2 are both greater than 0, the placeholder displays the correct value.
- When $totalc is 1 or more and $totalc2 is 0, the placeholder displays the correct value.
- When $totalc is 0 and $totalc2 is 1 or more, the placeholder has no value in it and the counter displays nothing.
All the products are showing up properly. I know that it's not a problem with the $total variable; I tried putting it onto the page by returning it, and it has the correct value when $totalc is 0 and $totalc2 is 1 or more. No error messages are showing up in the error_log file.
Does anyone have any idea what could be causing this?