Krapoutchniek Posted March 19, 2015 Share Posted March 19, 2015 (edited) Hi there, I'm new on Prestashop and I've got two problems : 1) I am currently developping modules. One of them can create and manage news displayed on the home page. Each news can be viewed on its own page and uses this type of link : /module/dashhomenews/newschampagne?id=1 I want to rewrite thoses links : /news-champagne/1-this-is-a-news where 1 is the id and this-is-a-news, the title of the news. For the moment I just want to rewrite the link so only the id appears. I've tried to override Dispatcher.php. It didn't work. Now I directly create my new route in the module's class. Here is the code : <?php class DashHomeNews extends Module { public static $ModuleRoutes = array( 'news-route' => array( 'controller' => null, 'rule' => 'news-champagne/{id[spam-filter]', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id') ), 'params' => array( 'fc' => 'module' ) )); public function __construct() { $this->name = 'dashhomenews'; $this->tab = 'dashboard'; $this->version = 1.0; $this->author = 'Yvan le Fevere de ten Hove'; $this->displayName = $this->l('News'); $this->description = $this->l('News on the home page.'); parent :: __construct(); } public function install() { $tab = new Tab(); $tab->class_name = 'AdminNews'; $tab->id_parent = 12; // 12 = ID du menu promotions $tab->module = $this->name; $languages = Language::getLanguages(); foreach ($languages as $language) { $tab->name[$language['id_lang']] = $this->l('News'); } $tab->add(); $sql= "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."news`( `id_news` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , `date` DATETIME NOT NULL, `active` BOOLEAN DEFAULT 1 NOT NULL)"; if(!$result=Db::getInstance()->Execute($sql)) return false; $sql= "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."news_lang`( `id_news` INT(11) NOT NULL, `id_lang` INT(11) NOT NULL, `title` TEXT NOT NULL, `summary` TEXT NOT NULL, `name` TEXT NOT NULL)"; if(!$result=Db::getInstance()->Execute($sql)) return false; return parent :: install() && $this->registerHook('home') && $this->registerHook('ModuleRoutes'); } public function uninstall() { Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'news`'); Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'news_lang`'); $tab = new Tab(Tab::getIdFromClassName('AdminNews')); $tab->delete(); parent::uninstall(); } public function hookDisplayHome($params) { global $smarty; $this->context->controller->addCSS(_MODULE_DIR_.'/dashhomenews/css/news.css'); $sql = new DbQuery(); $sql->select('*'); $sql->from('news', 'N'); $sql->innerJoin('news_lang', 'NL', 'N.id_news = NL.id_news'); $sql->where('N.active = 1 AND NL.id_lang = ' . (int)$this->context->language->id); $sql->orderby('N.date DESC'); $sql->limit(3); $tab_news = Db::getInstance()->ExecuteS($sql); $smarty->assign('language', $this->context->language->id); $smarty->assign('tab_news', $tab_news); return $this->display(__FILE__, 'home.tpl'); } public function hookModuleRoutes() { return self::$ModuleRoutes; } } But it doesn't work neither. And even if it workd, I don't know how to create the link with $this->getPageLink() in tpl file 2) For another module (one that shows price ranges) I need to add a link on the top menu. This link has to act like categories : the main link (called "Prices") has "sub-links" (each one is a price range). As I don't want the admin to link himself a product and a price rang (this is automatically done, based on the product's price), thoses price ranges can be categories. This is something else. I created tables in myd DB for that. How can I add this link to the top menu? Thank you. (sorry for my english, I'm French speaker) Edited March 19, 2015 by Krapoutchniek (see edit history) Link to comment Share on other sites More sharing options...
Krapoutchniek Posted March 20, 2015 Author Share Posted March 20, 2015 Please someone help a newbie Link to comment Share on other sites More sharing options...
Krapoutchniek Posted March 24, 2015 Author Share Posted March 24, 2015 Noone can help me? Link to comment Share on other sites More sharing options...
Krapoutchniek Posted March 24, 2015 Author Share Posted March 24, 2015 Ok so nobody wants to help... I finally found the solution. I share it here. So other people won't need to wait for answers that will never come... I just made a little mistake when defining my new route, but it was explained nowhere but here : https://www.packtpub.com/books/content/using-front-controllers-create-new-page (Great thanks to this guy) Here was my route : public static $ModuleRoutes = array( 'dashhomenews-newschampagne-route' => array( 'controller' => 'newschampagne', 'rule' => 'news-champagne/{id}', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id') ), 'params' => array( 'fc' => 'module', 'module' => 'dashhomenews' ) )); But in fact, you must name it "module-module_name-controller_name" and nothing else! So the correct code is : public static $ModuleRoutes = array( 'module-dashhomenews-newschampagne' => array( 'controller' => 'newschampagne', 'rule' => 'news-champagne/{id}', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id') ), 'params' => array( 'fc' => 'module', 'module' => 'dashhomenews' ) )); Maybe someone can help me for point 2? 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