OUR BLOG:

Prestahop Admin Login Page — header.tpl

For those of you who are just looking to copy/paste click on the the complete code or scroll to the bottom of the article…whichever is faster o_O So here is the problem, currently I’m running Prestashop 1.6.1.6 in one of my client’s websites and they ask me to make some modifications to the login admin page. The login admin page is the one we use to login to the back-end of your Prestashop installation. So in my mind, this was easy all I need to do was to find the login admin template override it and apply the needed modifications; yes and no. The first thing I did was to find the template files for the login admin page located at /_ADMIN_DIR_/themes/default/template/controllers/login/. In this folder you will find 4 files (3 files really since we don’t care about the index.php):
  1. content.tpl
  2. header.tpl
  3. layout.tpl
  4. index.php(This one we don’t care about)
In Prestashop  version  1.6.1.6 you can override the content of the login admin page, but you CANNOT override the header of login admin page, sigh. Meaning, we can override the content.tpl file, by making a copy of the file and placing it at /override/controllers/admin/templates/login/ but a copy of the header.tpl won’t update the content of the login admin page. Whatever new content you place into the content.tpl file inside the override folder will be reflected on the login page. Again, we are talking about the login admin page the one you use to access the back-end of your website NOT the one your customers use to place orders. So to the get the ball rolling and if you are new to the overriding process, please follow the instructions step…by step.
  1. Override AdminControllerCore class located in root/classes/controller/AdminController.php
  2. Find and override the display method — public function display()
  3. Now you can override your header.tpl located in the root/_ADMIN_DIR_/themes/default/template/controllers/login/header.tpl

1

First step is to locate the public function display() in the AdminController
$dir = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;
Now comment out or delete the following 2 lines of code:
$dir = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;
$header_tpl = file_exists($dir.'header.tpl') ? $dir.'header.tpl' : 'header.tpl';
Then replace those lines of code with the following:
$dir = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;
$dir_core = $this->context->smarty->getTemplateDir(0) .'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;

if(file_exists($dir.'header.tpl')){
    $header_tpl = $dir.'header.tpl';
}elseif(file_exists($dir_core.'header.tpl')){
    $header_tpl = $dir_core.'header.tpl';
}else{
   $header_tpl = 'header.tpl';
}
For those of you who are a little curious you can see that the footer and modules have the same problem as the header. Here it is, this is the final version of AdminController file located at
<?php
/**
 * 2007-2016 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 *
 *  @author 	PrestaShop SA <[email protected]>
 *  @copyright  2007-2016 PrestaShop SA
 *  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 *  International Registered Trademark & Property of PrestaShop SA
 */

class AdminController extends AdminControllerCore{

    /**
     * @return void
     * @throws Exception
     * @throws SmartyException
     */
    public function display(){

        $this->context->smarty->assign(array(
            'display_header' => $this->display_header,
            'display_header_javascript'=> $this->display_header_javascript,
            'display_footer' => $this->display_footer,
            'js_def' => Media::getJsDef(),
        ));

        // Use page title from meta_title if it has been set else from the breadcrumbs array
        if (!$this->meta_title) {
            $this->meta_title = $this->toolbar_title;
        }
        if (is_array($this->meta_title)) {
            $this->meta_title = strip_tags(implode(' '.Configuration::get('PS_NAVIGATION_PIPE').' ', $this->meta_title));
        }
        $this->context->smarty->assign('meta_title', $this->meta_title);

        $template_dirs = $this->context->smarty->getTemplateDir();
      //print_r($this->context->smarty->template_dir);
        // Check if header/footer have been overriden

        $dir = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;
        $dir_core = $this->context->smarty->getTemplateDir(0) .'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;
        if(file_exists($dir.'header.tpl')){
            $header_tpl = $dir.'header.tpl';
        }elseif(file_exists($dir_core.'header.tpl')){
            $header_tpl = $dir_core.'header.tpl';
        }else{
            $header_tpl = 'header.tpl';
        }
 
        $module_list_dir = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.'modules_list'.DIRECTORY_SEPARATOR;
        $module_list_dir_core = $this->context->smarty->getTemplateDir(0).'helpers'.DIRECTORY_SEPARATOR.'modules_list'.DIRECTORY_SEPARATOR;

        //$header_tpl = file_exists($dir.'header.tpl') ? $dir.'header.tpl' : 'header.tpl';

        //print_r($module_list_dir);
        
        
        if(file_exists($dir.'footer.tpl')){
             $footer_tpl = $dir.'footer.tpl';
        }elseif(file_exists($dir_core.'footer.tpl')){
              $footer_tpl = $dir_core.'footer.tpl';
        }else{
            $footer_tpl = 'footer.tpl';
        }
        //$footer_tpl = file_exists($dir.'footer.tpl') ? $dir.'footer.tpl' : 'footer.tpl';
        if(file_exists($module_list_dir.'modal.tpl')){
            $modal_module_list = $module_list_dir.'modal.tpl';
        }elseif(file_exists($module_list_dir_core.'modal.tpl')){
            $modal_module_list = $module_list_dir_core.'modal.tpl';
        }else{
            $modal_module_list = 'modal.tpl';
        }
       // $modal_module_list = file_exists($module_list_dir.'modal.tpl') ? $module_list_dir.'modal.tpl' : 'modal.tpl';
        $page_header_toolbar = file_exists($dir.'page_header_toolbar.tpl') ? $dir.'page_header_toolbar.tpl' : 'page_header_toolbar.tpl';
        $tpl_action = $this->tpl_folder.$this->display.'.tpl';

        // Check if action template has been overriden
        foreach ($template_dirs as $template_dir) {
            if (file_exists($template_dir.DIRECTORY_SEPARATOR.$tpl_action) && $this->display != 'view' && $this->display != 'options') {
                if (method_exists($this, $this->display.Tools::toCamelCase($this->className))) {
                    $this->{$this->display.Tools::toCamelCase($this->className)}();
                }
                $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action));
                break;
            }
        }

        if (!$this->ajax) {
            $template = $this->createTemplate($this->template);
            $page = $template->fetch();
        } else {
            $page = $this->content;
        }

        if ($conf = Tools::getValue('conf')) {
            $this->context->smarty->assign('conf', $this->json ? Tools::jsonEncode($this->_conf[(int)$conf]) : $this->_conf[(int)$conf]);
        }

        foreach (array('errors', 'warnings', 'informations', 'confirmations') as $type) {
            if (!is_array($this->$type)) {
                $this->$type = (array)$this->$type;
            }
            $this->context->smarty->assign($type, $this->json ? Tools::jsonEncode(array_unique($this->$type)) : array_unique($this->$type));
        }

        if ($this->show_page_header_toolbar && !$this->lite_display) {
            $this->context->smarty->assign(
                array(
                    'page_header_toolbar' => $this->context->smarty->fetch($page_header_toolbar),
                    'modal_module_list' => $this->context->smarty->fetch($modal_module_list),
                )
            );
        }

        $this->context->smarty->assign(
            array(
                'page' =>  $this->json ? Tools::jsonEncode($page) : $page,
                'header' => $this->context->smarty->fetch($header_tpl),
                'footer' => $this->context->smarty->fetch($footer_tpl),
            )
        );

        $this->smartyOutputContent($this->layout);
    }
}
 
Posts created 22
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments