Created
November 30, 2016 10:10
-
-
Save devnix/7382fd44dc1a209f01de02a3ba7590b0 to your computer and use it in GitHub Desktop.
Render the Prestashop's blockcart module in Wordpress (or any external script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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