Woolwich Posted January 13, 2013 Share Posted January 13, 2013 Hello! How can I add following code to the module blocktopmenu? Should I create a new module or edit blocktopmenu.php? $url = 'http://graph.facebook.com/google'; echo json_decode(file_get_contents($url))->{'likes'}; My PHP knowledge is very limited. Regards, Woolwich Link to comment Share on other sites More sharing options...
vekia Posted January 14, 2013 Share Posted January 14, 2013 add php code to the blocktopmenu.php file what you exactly want to do? Link to comment Share on other sites More sharing options...
Woolwich Posted January 14, 2013 Author Share Posted January 14, 2013 add php code to the blocktopmenu.php file what you exactly want to do? I want to show number of likes in the top menu. I have never worked with tpl files and Prestashop before and my PHP knowledge is very limited so I'm very confused. The code that I posted in the first post works, the question is just how to get it to the blocktopmenu.tpl. Link to comment Share on other sites More sharing options...
vekia Posted January 14, 2013 Share Posted January 14, 2013 so the main questions is which version of prestashop you use? Link to comment Share on other sites More sharing options...
vekia Posted January 14, 2013 Share Posted January 14, 2013 i prepared it for 1.5.x versions: you must paste first function before the public function hookDisplayTop($param) and replace public function hookDisplayTop($param) by function that i pasted below public function getlikes(){ $url = 'http://graph.facebook.com/google'; return json_decode(file_get_contents($url))->{'likes'}; } public function hookDisplayTop($param) { $this->user_groups = ($this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'))); $this->page_name = Dispatcher::getInstance()->getController(); $smarty_cache_id = 'blocktopmenu-'.$this->page_name.'-'.(int)$this->context->shop->id.'-'.implode(', ',$this->user_groups).'-'.(int)$this->context->language->id.'-'.(int)Tools::getValue('id_category').'-'.(int)Tools::getValue('id_manufacturer').'-'.(int)Tools::getValue('id_supplier').'-'.(int)Tools::getValue('id_cms').'-'.(int)Tools::getValue('id_product'); $this->context->smarty->cache_lifetime = 31536000; Tools::enableCache(); if (!$this->isCached('blocktopmenu.tpl', $smarty_cache_id)) { $this->makeMenu(); $this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH')); $this->smarty->assign('MENU', $this->_menu); $this->smarty->assign('this_path', $this->_path); } $this->smarty->assign('likes',$this->getlikes()); $this->context->controller->addJS($this->_path.'js/hoverIntent.js'); $this->context->controller->addJS($this->_path.'js/superfish-modified.js'); $this->context->controller->addCSS($this->_path.'css/superfish-modified.css'); $html = $this->display(__FILE__, 'blocktopmenu.tpl', $smarty_cache_id); Tools::restoreCacheSettings(); return $html; } next in template file blocktopmenu.tpl you can put {$likes} anywhere you want Link to comment Share on other sites More sharing options...
Woolwich Posted January 14, 2013 Author Share Posted January 14, 2013 I'm running 1.4 but I managed to modify your code so that it works. Thanks alot for the help! Link to comment Share on other sites More sharing options...
vekia Posted January 15, 2013 Share Posted January 15, 2013 you are welcome, i marked this topic as solved Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now