Jump to content

Call function from product-price.tpl


polaije

Recommended Posts

Hello,

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 :

Quote

public function isMed($prod)

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

$listing=$cat->id_parent;


   foreach ($listing as $list)
    {
   if($list['level_depth']==2)
   {
    break;
    
   }
  
    }
    if($list['id_category']==3)
    return true;
   else
    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>
        </div>
      {/if}
 {/if}
 
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.
 
Jean-Marie
 

 

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

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...