Jump to content

Call function from product-price.tpl


Recommended Posts


This a simple question about Calling a function from a tpl file.

I need to override the discount display that appears on the product page , depending of the category-default parent.
In the productcontroller.php I have entered a new function :


public function isMed($prod)

$cat = new Category($prod['id_category_default'], $this->context->language->id);


   foreach ($listing as $list)
    return true;
    return false;




I try to call this function from product-price.tpl where I have :
 {if $product->isMed($product)==false}
   {if $product.has_discount}
        <div class="product-discount">
          {hook h='displayProductPriceBlock' product=$product type="old_price"}
          <span class="regular-price">{$product.regular_price}</span>
I have an error on the product page :
FatalErrorException in smarty_internal_templatebase.php(157) : eval()'d code line 1033: Error: Call to a member function isMed() on array

I debug the function with no code just a return true and the result is the same. I dont see where I get an array in my call.
I am new in PHP and smarty, can someone help me.



Link to comment
Share on other sites

  • 3 weeks later...


You cannot use the function isMed() in product-price.tpl as you had defined the function in the productController.php. To use the isMed() function in tpl file. define the isMed() function in class file i.e.  /classes/Product.php

Alternative method:

Simply assign the function value from the controller to .tpl instead of calling the function in .tpl file.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...