Jump to content

Use Category.php function result in header.tpl


Recommended Posts

Hey!

 

I'm trying to create a title tag for my categories in the form of "Products starting from <lowest_price>", where <lowest_price> is the lowest price from any of the products in that category.

 

I've used https://www.prestashop.com/forums/topic/219867-solved-display-lowest-price-of-subcategory-in-listing/ to get the Category.php function that gets the lowest price from the products within a category, given its id.

 

However, I am unsure how to get the result of that function all the way to the header.tpl file.

 

Any ideas?

 

Thanks!

 

 

Link to comment
Share on other sites

Can't seem to make it work.

 

Currently I have in my Category.php file:

/**
  * Return lowest price in a specific (sub)category
  *
  * @param integer $id_category Indicates the category ID of that the lowest price will be looked up
  */
public function getLowestPriceOfCategory( $id_category ) {
   if( !Validate::isInt( $id_category ) ) {
	  die( Tools::displayError() );
   }

   $sql = 'SELECT MIN( p.price ) lowest_price
	 FROM `'._DB_PREFIX_.'product` p
	 INNER JOIN `'._DB_PREFIX_.'category` c
	 ON (p.`id_category_default` = c.`id_category` AND c.`id_category` = ' . (int) $id_category . ')
	 GROUP BY c.`id_category`;';
  
   $result = Db::getInstance( _PS_USE_SQL_SLAVE_ )->getRow( $sql );
  
   return $result['lowest_price'];
}

I added "static" after "public", then went in header.tpl and tried {Category::getLowestPriceOfCategory($category->id)}, but didn't seem to work (500 error).

 

Am I doing it wrong? :)

  • Like 1
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...