Skip to content

Instantly share code, notes, and snippets.

@devnix
Created November 30, 2016 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devnix/7382fd44dc1a209f01de02a3ba7590b0 to your computer and use it in GitHub Desktop.
Save devnix/7382fd44dc1a209f01de02a3ba7590b0 to your computer and use it in GitHub Desktop.
Render the Prestashop's blockcart module in Wordpress (or any external script)
<?php
// Prestashop's root folder, in my example Prestashop is installed in the root folder, and Wordpress is installed in /blog
define('PRESTASHOP_ROOT', ABSPATH.'..');
// Still don't know if necessary
// require PRESTASHOP_ROOT.'/config/settings.inc.php';
// require PRESTASHOP_ROOT.'/config/defines.inc.php';
// Essential Prestashop require to bootstrap and load dependencies
require PRESTASHOP_ROOT.'/config/config.inc.php';
// Load the desired module to render
require PRESTASHOP_ROOT.'/modules/blockcart/blockcart.php';
// Nope. This seems to load the entire Prestashop and throw a 404
// Dispatcher::getInstance()->dispatch();
// Seems like it is required to get the context filled
if (isset(Context::getContext()->controller)) {
$controller = Context::getContext()->controller;
} else {
$controller = new FrontController();
$controller->init();
}
// Get the cookie and the cart from context (we need params to call the hook)
$context = Context::getContext();
$hook_args = [
'cookie' => $context->cookie,
'cart' => $context->cart
];
// Initialize the module
$blockcart = new BlockCart();
// Display the top hook (rendering Smarty, etc)
echo $blockcart->hookTop($hook_args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment