Search code examples
moduleprestashoptransplant

prestashop 1.4 transplant home featured module in a new hook


i am trying to move home featured products outside of the columns div in a "newdiv" as follow:

<header>
    hook header
</header> 
<container>
    <div central_column>
    .
    <!-- here is the featured products block -->
    .
    </div>
    <div right_column>
        hook right column
    </div>
</container>

<newdiv><--! here where i want to show featured products --></newdiv>

<footer>
    hook footer
</footer>

to do this i edited FrontController.php adding the hook to display footer ( 'HOOK_FEATURED_HOME' => Module::hookExec('homeFeatured') ):

public function displayFooter()
    {

        if (!self::$initialized)
            $this->init();

        self::$smarty->assign(array(
            'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => self::$cart)),
            'HOOK_FEATURED_HOME' => Module::hookExec('homeFeatured'),
            'HOOK_FOOTER' => Module::hookExec('footer'),
            'content_only' => (int)(Tools::getValue('content_only'))));
        self::$smarty->display(_PS_THEME_DIR_.'footer.tpl');
        //live edit
        if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND  (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
    {
        self::$smarty->assign(array('ad' => $ad, 'live_edit' => true));
        self::$smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl');
    }
    else
        Tools::displayError();
}

on the file footer.tpl i added the hook:

           <!-- featured products -->
            {if $page_name == 'index'}
                <div id="homeFeatured">
                    {$HOOK_FEATURED_HOME}
                </div>
            {/if}

i added in the DB

id     name           title                     descritption             position       live_edit

97    homeFeatured    Home Featured Products    NULL                     0                  0

in module/homefeatured/homefeatured.php i added:

function install()
    {
        if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) OR !parent::install() OR !$this->registerHook('home') OR !$this->registerHook('homeFeatured'))
            return false;
        return true;
    }

and at the end of the class

function homeFeatured($params)
    {
    //    return $this->hookHome($params);
        echo 'hook test';

    }

i didn't see anything in the div newdiv.

when i try to transplant the module to the new hook in the back office i receive:

This module cannot be transplanted to this hook.

Solution

  • Gave the solution in a comment but I write an answer in case someone else needs it:

    When you edit the install() function of a module you need to uninstall and re-install it after