Forum


Calc Builder Support

Calc Builder support
Forums
Public write access is disabled. Please login

sections, arrays and sums 27.02.2016 21:08

I need to calculate the total volume and weight of boxes. So a site visiter needs to imput the length, width, height and weight of a number of boxes.

For this I want to create four fields in a repeating section.

How do I code that for each box I get a volume, a total volume for all boxes and a total weight.

I also want to count how many lengths are >120cm
and how many boxes weigh more than 30kg

Re: sections, arrays and sums 29.02.2016 09:16

Hi,
the steps to build that calculator would be:

-Create your input fields (length, width, height and weight) typed as 'number'

-Create a new field 'volume' typed as 'inline result'

-Create a new section and select all of them to be included

-Create your input layout. Form layout->select your section tab and insert your fields or use the helper buttons to do it automatically.

- Code section: you need to iterate all lines to get the result, the code would be like:

$totalvolume=0;
for($i=0;count($length)>$i;$i++){
$volume[$i]=$length[$i]*$width[$i]*$height[$i];
$totalvolume=$totalvolume+$volume[$i];

}


This will fill the 'volume' result for each line, and also calculate a total that you can print at the exit layout using ##totalvolume##


You can add a totalweight following the same pattern and also create your other needed results.


Hope this helps, regards
Moonsoft Team
www.moonsoft.es

Re: sections, arrays and sums 02.03.2016 15:09

Hi

No, it doesn't calculate.
I allways get 0.

Something else is strange. In the layout form I put all the fields next to each other and these appear vertically on the site.

Re: sections, arrays and sums 02.03.2016 16:09

Hi,
if you get a result the calculator is working, if the final result is 0 there is something wrong at your code or configuration. Please double check if the section is properly configured, for example printing as a result the number of lines $result=count($length);

and also that your fields are named exactly as your code (length, width, height).

About the layout, the style you set with the html editor inside the module is applied, but as the module is loaded inside your page, some styles from your template can be inherited affecting to the final look, as it happens with any other module.

If you can't get the code working please export your calculator and attach it to a ticket of your helpdesk, we'll take a look and let you know how to adjust.

Regards
Moonsoft Team
www.moonsoft.es

Re: sections, arrays and sums 02.03.2016 17:26

I started all over again. All problems solved!

For those interested here's the code for the weight.


$totalweight=0;
for($i=0;count($weight)>$i;$i++){
$weight[$i]=$weight[$i];
$totalweight=$totalweight+$weight[$i];


Thank you!

Koen
Are you satisfied with our products/services/support?
Please help us to keep improving, add a review at  joomla extensions site and  magento connect

Our clients' feedback