Question

I am trying to initiate the AdminController module from outside the Prestashop. Basically, I am creating an external program which uses Prestashop to get current employee for which I should instantiate the AdminController, but its throwing error.

Many modules init the FrontController but I cannot find any example for AdminController like :

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');

Please advice.

Was it helpful?

Solution

I found the solution after all. Simply define _PS_ADMIN_DIR_ and init the config.inc.php, Prestashop will automatically load the admin environment. However, if you are loading this from a module, its tricky to find the admin directory as its not defined anywhere, so I have written this small script.

$admindir = '';
foreach (glob("../../*/ajaxfilemanager", GLOB_ONLYDIR) as $filename) {
    $admindir = str_replace('../../', '', $filename);
    $admindir = str_replace('/ajaxfilemanager', '', $admindir);

}
define('_PS_ADMIN_DIR_', getcwd().'/../../'.$admindir);
require(_PS_ADMIN_DIR_.'/../config/config.inc.php');

Enjoy!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top