Prestashop Folder

Using Prestashop App From Script Located Outside Prestashop Folder


Magento is a well structured Zend project and it’s easy to bootstrap the app to use it outside HTTP front controller, PrestaShop is another story it’s really a big mess of spaghetti code, to bootstrap the app really depends os PS version and in some cases on installed modules that changes core behaviour.

To start you can first include the config/ file that is on PS root dir, this will init the PS classloader and a bunch of configuration defines, if you use another autoloader and a old version on PS (<1.6) you need to workaround it, this is a simple bootstrap code that allow make any PS call:

// Load PS config and autoloader
define ('PS_DIR', __DIR__ . '/../ps-wtf');
require_once PS_DIR .'/config/';

// I use this to load compoper dependencies
require_once __DIR__ . '/../vendor/autoload.php';

// Call old __autoload() if present, required for PrestaShop old versions
if (function_exists('__autoload')) {
    spl_autoload_register(function ($className) {

// Init Shop context, required some operation will fail without it
// adust accordly to multistore PS >= 1.6

// Init PS context, some modules require that this context was initialized and with correct data
// some core function fired in the admin require at least a employee
define ('PS_DEFAULT_EMPLOYEE', 1);
$psContext = Context::getContext();
if (!$psContext->employee) {
    $psContext->employee = new Employee(PS_DEFAULT_EMPLOYEE);

// You can make any API call
$cat = new Category();
$cat->name = [
    1 => 'New',
    2 => 'Nuevo',
$cat->id_parent = 1;

echo $cat->id;

Some PS functionality depends on correct initialization of some core classes (Yes it’s crazy), you can take a look at ControllerCore and FrontControllerCore to see what is happening in the normal PS request flow.

I hope that this can help.


Please enter your comment!
Please enter your name here