NemoPS Posted January 19, 2015 Share Posted January 19, 2015 EDIT: my tutorial: http://nemops.com/override-prestashop-modules-core/#.VLzfbkejOr1 Hey everyone. Razaro, another user of the forum, just noticed some code in module.php where overrides are mentioned, this: public static function getInstanceByName($module_name) { if (!Validate::isModuleName($module_name)) { if (_PS_MODE_DEV_) die(Tools::displayError(Tools::safeOutput($module_name).' is not a valid module name.')); return false; } if (!isset(self::$_INSTANCE[$module_name])) { if (Tools::file_exists_no_cache(_PS_MODULE_DIR_.$module_name.'/'.$module_name.'.php')) { include_once(_PS_MODULE_DIR_.$module_name.'/'.$module_name.'.php'); if (Tools::file_exists_no_cache(_PS_OVERRIDE_DIR_.'modules/'.$module_name.'/'.$module_name.'.php')) { include_once(_PS_OVERRIDE_DIR_.'modules/'.$module_name.'/'.$module_name.'.php'); $override = $module_name.'Override'; if (class_exists($override, false)) return self::$_INSTANCE[$module_name] = new $override; } if (class_exists($module_name, false)) return self::$_INSTANCE[$module_name] = new $module_name; } return false; } return self::$_INSTANCE[$module_name]; } In presta .11. It was not there in .09 so do we have to presume we can now override modules' php files as well? I didn't test .11 yet so that's why i'm asking, in case anyone did. Of course it's not mentioned in the changelog Link to comment Share on other sites More sharing options...
NemoPS Posted January 19, 2015 Author Share Posted January 19, 2015 Ok, it is possible indeed. Guys, why are we not being informed? I'm writing a tut 1 Link to comment Share on other sites More sharing options...
cristic Posted January 19, 2015 Share Posted January 19, 2015 The piece of code clearly enables now module overrides. It should have been documented. Link to comment Share on other sites More sharing options...
stratboy Posted February 2, 2015 Share Posted February 2, 2015 Great! Hey, are you from Italy??? Link to comment Share on other sites More sharing options...
wakabayashi Posted February 8, 2015 Share Posted February 8, 2015 Hello Nemo I followed your tutorial but I don't get it to work. I want to override blocktopmenu. My Code is: <?php if (!defined('_CAN_LOAD_FILES_')) exit; class BlockTopMenuOverride extends BlockTopMenu { private function getCMSMenuItems($parent, $depth = 1, $id_lang = false) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; if ($depth > 3) return; $categories = $this->getCMSCategories(false, (int)$parent, (int)$id_lang); $pages = $this->getCMSPages((int)$parent); if (count($categories) || count($pages)) { $this->_menu .= '<ul>'; foreach ($categories as $category) { $cat = new CMSCategory((int)$category['id_cms_category'], (int)$id_lang); /* Genzo Change */ if ($cat->id==5 ) { $this->_menu .= '<li>'; if ($_SERVER['SERVER_NAME']=="www.chesspoint.ch" or "www.webpoint-schiendorfer.ch") { /* man benötigt diese Condition zur Zeit eigentlich nicht, aber es könnte hilfreich sein, wenn man mal mit mehreren Shops arbeitet */ $this->_menu .= '<a href="/blog">'.$category['name'].'</a>'; } else { $this->_menu .= '<a href="#">'.$category['name'].'</a>'; } $this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1); $this->_menu .= '</li>'; } else { /* End Genzo Change */ $this->_menu .= '<li>'; $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($cat->getLink()).'">'.$category['name'].'</a>'; $this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1); $this->_menu .= '</li>'; } /* Genzo Change */ } /* End Genzo Change */ /* Genzo Change Original foreach ($pages as $page) { $cms = new CMS($page['id_cms'], (int)$id_lang); $links = $cms->getLinks((int)$id_lang, array((int)$cms->id)); $selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : ''; $this->_menu .= '<li '.$selected.'>'; $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>'; $this->_menu .= '</li>'; }*/ /* Genzo Change */ foreach ($pages as $page) { $cms = new CMS($page['id_cms'], (int)$id_lang); $links = $cms->getLinks((int)$id_lang, array((int)$cms->id)); $selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : ''; $this->_menu .= '<li '.$selected.'>'; if ($cms->id==11){ $this->_menu .= '<a href="/blog/chesspoint">'.$cms->meta_title.'</a>'; } elseif ($cms->id==12){ $this->_menu .= '<a href="/blog/schachturniere">'.$cms->meta_title.'</a>'; } elseif ($cms->id==13){ $this->_menu .= '<a href="/blog/schachgeschichte">'.$cms->meta_title.'</a>'; } elseif ($cms->id==7){ $this->_menu .= '<a href="/faq">'.$cms->meta_title.'</a>'; } else { $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>'; } $this->_menu .= '</li>'; } /* End Genzo Change */ $this->_menu .= '</ul>'; } } } Whats wrong with this override? I doesn't make anything I tried to delete class_index.php, but this file always comes back. Is this normal? Link to comment Share on other sites More sharing options...
NemoPS Posted February 9, 2015 Author Share Posted February 9, 2015 Firstly, is the override taking place? I mean if you use die(); somewhere in the hook, does it die? Link to comment Share on other sites More sharing options...
PascalVG Posted February 9, 2015 Share Posted February 9, 2015 Waka, Can it be because the function is defined as private? http://php.net/manual/en/language.oop5.visibility.php My 2 cents, pascal Link to comment Share on other sites More sharing options...
NemoPS Posted February 11, 2015 Author Share Posted February 11, 2015 You might have a point, I missed that. Still, it should spawn an error if so, weird Link to comment Share on other sites More sharing options...
wayann Posted February 27, 2015 Share Posted February 27, 2015 ah! goot to know I'm not the only one... Overriding blocktopmenu function generateCategoriesMenu with this code does not work class BlocktopmenuOverride extends Blocktopmenu { public function generateCategoriesMenu($categories, $is_children = 0) { die( var_dump ('hello I am an override') ); } } if I comment the parent function it works as expected I've asked why in this post but so far nobody can tell why... https://www.prestashop.com/forums/topic/420461-cant-override-blocktopmenu-function-generatecategoriesmenu/ Link to comment Share on other sites More sharing options...
bellini13 Posted February 27, 2015 Share Posted February 27, 2015 most likely a defect. report the issue to Prestashop using their Forge, only way they will see or fix it Link to comment Share on other sites More sharing options...
wayann Posted February 27, 2015 Share Posted February 27, 2015 (edited) most likely a defect. report the issue to Prestashop using their Forge, only way they will see or fix it Hi @bellini13, thx for the quick reply pushed patch to dev branch don't want to clone anymore modules... Edited February 27, 2015 by wayann (see edit history) 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