Kennedy5020 Posted June 3, 2013 Share Posted June 3, 2013 I need to display product favorite count and some other functionalites in product detail page (product.tpl page). But i am new to prestashop.so i am unable to find the where i declared function and i dont how to call the function form tpl file. Here i write product favorite count code public function favcount($id_product) { $sql = 'SELECT count(*) FROM `ps_favorite_product` WHERE `id_product`='.(int)$id_product.; $result = Db::getInstance()->getRow($sql); return $result['count']; } in which place i can insert the above code and how to call from product.tpl file any one help ? 1 Link to comment Share on other sites More sharing options...
vekia Posted June 3, 2013 Share Posted June 3, 2013 well, you should edit product controller (add variable to the smarty array) then you will be able to display it (variable) in the .tpl file please give me information about your prestashop version, i will show you how to achieve this. 1 Link to comment Share on other sites More sharing options...
Kennedy5020 Posted June 3, 2013 Author Share Posted June 3, 2013 well, you should edit product controller (add variable to the smarty array) then you will be able to display it (variable) in the .tpl file please give me information about your prestashop version, i will show you how to achieve this. thanks venkia.I am using PrestaShop™ 1.5.4.1 Link to comment Share on other sites More sharing options...
vekia Posted June 3, 2013 Share Posted June 3, 2013 thanks for informations. Okay, so open the classes/Product.php file add your function to the controller, but change it a bit, here is a correct code: public static function favcount($id_product){ $sql = 'SELECT count(*) AS count FROM `ps_favorite_product` WHERE `id_product`='.(int)$id_product; $result = Db::getInstance()->getRow($sql); return $result['count']; } then in .tpl file (product.tpl located in your theme) you can use: {Product::favcount(Tools::getvalue('id_product'))} 8 Link to comment Share on other sites More sharing options...
Kennedy5020 Posted June 3, 2013 Author Share Posted June 3, 2013 thanks for informations. Okay, so open the classes/Product.php file add your function to the controller, but change it a bit, here is a correct code: public static function favcount($id_product){ $sql = 'SELECT count(*) AS count FROM `ps_favorite_product` WHERE `id_product`='.(int)$id_product; $result = Db::getInstance()->getRow($sql); return $result['count']; } then in .tpl file (product.tpl located in your theme) you can use: {Product::favcount(Tools::getvalue('id_product'))} thank you very much. I got .what i am exactly need. Link to comment Share on other sites More sharing options...
vekia Posted June 3, 2013 Share Posted June 3, 2013 you're welcome so im going to mark this thread as [solved] regards Link to comment Share on other sites More sharing options...
Recommended Posts