Search code examples
magentomathphpadminhtml

Getting Helper Data php in magento


Have been trying to get a variable percentage from two helper functions inside .phtml file in magento

basically i have two variables based on two helper functions that on their own output/echo static numbers. Problem is in the below php they are just displaying as the value and not dividing/multiplying. So like i said the helper data & module work is using the data as variables to do/complete the equation within the .phtml file. See code below

get->FunctionA() just equals a round number value (from a collection)

get->FunctionB() just equals a round number value as well (from a collection)

probs not the best way but this just outputs two values from helper data and not dividing.

echo Mage::helper('module/data')->getFunctionA() / Mage::helper('module/data')->getFunctionB();

Also this does not work either, just produces the same result and is probs the best/easiest way

$dataA = Mage::helper('module/data')->getFunctionA(); 
$dataB = Mage::helper('module/data')->getFunctionB();
$result = ($dataA / $dataB) * 100;
echo $result;

Like i said above the values can be echoed (in either helper function or phtml files but the actual calculation does not wont to work

Any help would be great


Solution

  • Ok sorted the problem out. What was happening was that in the helper file the getFunctionA() & getFunctionB() value was being echoed when i should have been just returning the value then echoing the helper function in the .phtml file. Doh! See below the helper function example that is now working Woohoo!!!

    public function getFunctionA()
    {
    $FunctionA = Mage::getModel('module/collection')->getCollection();
    $FunctionA->addFieldToFilter('attribute', 'value_to_filter');
    $FunctionA->addFieldToFilter('status','1');
    return ''.count($FunctionA) . ''; //this line was the problem cause i was echoing & not returning the value
    
    }
    

    Now the value can be echoed in the phtml & the math equation is confirmed working

    $dataA = Mage::helper('module/data')->getFunctionA(); 
    $dataB = Mage::helper('module/core')->getFunctionB();
    $result = ($dataA / $dataB) * 100;
    echo $result;
    

    this code does the math and now i can rest.