3

This is my previous question: How to convert a decimal $attribute['text']; into a fraction in opencart

I have a helper function that is declared in startup.php and defined in helper/dec2frac.php

I am trying to call the helper function from a category.tpl file with this code:

  <?php if ($product['attribute_groups']) { ?>
                   <?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
                       <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
                        <?php /*var_dump($attribute);*/

                       if($attribute['name'] == "Adjuster Position")
                       {
                          //echo("<h1>HELLLO</h1>");
                          dec2frac($attribute['text']);
                       }


                        ?>

...but I am getting this error message:

Fatal error: Call to undefined function dec2frac() in startup.php helper/dec2frac.php

How can I call my helper function in the category.tpl file? Do I need to reference the helper function in my category.php file?

Community
  • 1
  • 1
Michael
  • 61
  • 1
  • 4

1 Answers1

0

I am trying to achieve same but in a different way. This following link will help, it will work with opencart v2.3x

Not able to find my custom object in Registry - OpenCart-v2.3.0.2

Try the above link (it is my posted question). Create a object and save it in registry and get it from registry and call the required function.

in your category.php file, get your object from registry. For eg:

$kt = $registry->get('ktLibrary'); //Object
$value = $kt->getSomeValue(); //function

object $kt will be available throughout the category.tpl file.

Community
  • 1
  • 1