sazr
sazr

Reputation: 25928

Override Prestashop Module Changes not Visible

I am attempting to override a module in Prestashop but the changes are just not appearing.

I have overridden a template file and a controller so I have added the following files:

\override\modules\blockwishlist\views\templates\front\mywishlist.tpl
\override\modules\blockwishlist\controllers\front\mywishlist.php

These are very simple changes where I add another column to a table that contains a button. When the button is clicked the controller generates a CSV file.

Any idea why these changes are just not being shown?

Note: I have turned on 'Force Compile' and turned of caching.

Edit: Re overridding a controller is it:

class BlockWishListMyWishListModuleFrontController extends BlockWishListMyWishListModuleFrontControllerCore // extends ModuleFrontController

or

class BlockWishListMyWishListModuleFrontControllerOverride extends BlockWishListMyWishListModuleFrontController

Upvotes: 0

Views: 1048

Answers (2)

Serge P
Serge P

Reputation: 1863

okay, I did some code research (maybe thre is exists easiest way, not sure), so:

in code Dispatcher class we have

// Dispatch module controller for front office
            case self::FC_MODULE :
                $module_name = Validate::isModuleName(Tools::getValue('module')) ? Tools::getValue('module') : '';
                $module = Module::getInstanceByName($module_name);
                $controller_class = 'PageNotFoundController';
                if (Validate::isLoadedObject($module) && $module->active) {
                    $controllers = Dispatcher::getControllers(_PS_MODULE_DIR_.$module_name.'/controllers/front/');
                    if (isset($controllers[strtolower($this->controller)])) {
                        include_once(_PS_MODULE_DIR_.$module_name.'/controllers/front/'.$this->controller.'.php');
                        $controller_class = $module_name.$this->controller.'ModuleFrontController';
                    }
                }
                $params_hook_action_dispatcher = array('controller_type' => self::FC_FRONT, 'controller_class' => $controller_class, 'is_module' => 1);
            break;

where we see that controllers loaded without overrides, but from other side below in code we see hook execution:

// Loading controller
            $controller = Controller::getController($controller_class);

            // Execute hook dispatcher
            if (isset($params_hook_action_dispatcher)) {
                Hook::exec('actionDispatcher', $params_hook_action_dispatcher);
            }

so one of possible solution (without overriding core class) :

  1. how to override module and hope you have core version >= 1.6.0.11

  2. in blockwishlist.php in install() method add

    this->registerHook('actionDispatcher')

to condition with other hooks, so it will looks like ... !this->registerHook('actionDispatcher') || ... because this hook not registered by default and we can't just place module there.

  1. create method (can't beautify code here)

    public function hookActionDispatcher($params) { if ('blockwishlistmywishlistModuleFrontController' == $params['controller_class']) { include_once(_PS_OVERRIDE_DIR_ . 'modules/' . $this->name . '/controllers/front/mywishlist.php'); $controller = Controller::getController('BlockWishListMyWishListModuleFrontControllerOverride'); } }

  2. you already have override/modules/blockwishlist/controllers/front/mywishlist.php file by this path

  3. reinstall module.

  4. it works!

more about overriding some behaviors in docs

Upvotes: 1

sazr
sazr

Reputation: 25928

Turns out that to override a module you dont place your files in:

~/overrides/module/MODULE_NAME

Instead you place it in:

~/themes/MY_THEME/modules/MODULE_NAME

Now the changes are exhibiting themselves.

Does anyone know if/when the module is auto-updated, will my changes get lost/overrwritten?

Upvotes: 0

Related Questions