• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Sum of a repeated group in the calc plugin

wouter.galia

New Member
Hi

I use the calc plug-in to calculate the sum of a repeated group with the code underneath (found in forum).
My setup is very much like the 'venues' and 'bands' tutorial.

Everything works fine except for when I have one item only. With only one item the result is '0'. With more then one item it works fine.

I also would like to put the '?' sign in front.

-----------------------

$fields = array('tablename___listname');
$total = 0;
foreach ($fields as $field)
{
$value = JArrayHelper::getValue($data, $field . '_raw', array());
$thisSum = array_sum($value);
$total += $thisSum;
}
return $total;

-----------------------

Best regards
 
Try just ...

Code:
$amounts = (array) $data['tablename___element'];
return '?' . array_sum($amounts);

-- hugh
 
This does the opposite. It only works with one item. With more then one item in the repeating group it returns '0'.

The ? sign is not needed anymore, it gives a conflict with fallowing calculations.
 
Use
$amounts = (array) $data['tablename___element_raw'];
fallowing calculations
You can't use a calc element in other calcs because you can't know which is calculated first.
 
Oops, yes, I accidentally left off the raw when I replaced my actual element name after testing that code.

Note that this won't work as expected if you calc on list display, with unmarked rows.

So set calc on save to yes.


Sent from my HTC One using Tapatalk
 
Perfect! That did it.

$amounts = (array) $data['tablename___element_raw''];
return array_sum($amounts);

Then when I use the result of this calc element in another calc element for calculating a discount, everything works fine.

Many thanks!
 
Last edited:
It's working on my site.
Make sure to have 3 underscores in your element name and set Joomla error reporting to max to see warnings and notices.
Do you have ajax calculation off or on?
Can you post a screenshot of your settings?
 
Oh yes, I should have done a reload before submitting the answer (opened it before lunch;))
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top