Jump to content

How to show product like count?


Recommended Posts

Hello,

 

I am trying to modify "favoriteproducts" module to show "product like count" near the button.

I wrote something but i cant pass the value from .php and show it in .tpl file.

 

FavoriteProduct.php

<?php
  class FavoriteProduct extends ObjectModel
  {
  public $id_product;
  public $favorite_count;


  public static function FavoriteProductsCount($id_product)
  {
    $favorite_count = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
    SELECT COUNT(*)
    FROM `'._DB_PREFIX_.'favorite_product`
    WHERE `id_product` = '.(int)$id_product
  );


  if ($favorite_count)
    return new FavoriteProduct($favorite_count);
  return null;
  }
}

I wrote this to favoriteproducts.php 

include_once(dirname(__FILE__).'/FavoriteProduct.php');

$this->smarty->assign('LikeCount', $favorite_count);

return $this->display(__FILE__, 'favoriteproducts-extra.tpl');

And favoriteproducts-extra.tpl

{$favorite_count}

But this didnt work. How can i pass the $favorite_count value from FavoriteProduct.php and show it in tpl file.

 

 

Edited by ajnglagla (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...