In controllers/front I created a controller named abandonedCarts:
class <moduleName>AbandonedCartsModuleFrontController extends ModuleFrontController
{
public function __construct()
{
parent::__construct();
$this->context = Context::getContext();
$this->store_debug('Controller - __construct');
}
public function initContent()
{
parent::initContent();
$this->store_debug('Controller - init');
}
}
where store_debug is a function that simply logs on the db something (just for check). Thanks to this I know that when I call the controller from URL in this way
site/index.php?fc=module&module=olyo&controller=abandonedCarts
the construct and init methods are being called, but what I need is the controller being called when the module is installed (or at its first start).
In the main file I also put in the constructor this line:
$this->controllers = array('abandonedCarts');
But I'm not sure I even need it
You can include the Controller and just call the object method like following :
<?php
class MyModule extends Module {
public install(){
$file = _PS_MODULE_DIR_.'/'.$this->name.'/controllers/front/default.php';
require_once $file;
$obj = new ObjectController();
$obj->my_super_method();
return true;
}
}
You don't need the controller parameter. You shall stick to what is include by default with Prestashop's Generator here : https://validator.prestashop.com/
You should not instantiate a FrontController in admin context, here is a workaround :
Your module :
<?php
class MyModule extends Module {
public install(){
$result = parent::install();
if ($result) {
$this->doStuff();
}
return $result;
}
public function doStuff() {
// do stuff
}
}
your controller
<?php
class <moduleName>AbandonedCartsModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->module->doStuff();
}
}