176 lines
5.6 KiB
PHP
176 lines
5.6 KiB
PHP
<?php
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
require_once dirname(__FILE__).'/classes/Simulator.php';
|
|
require_once dirname(__FILE__).'/classes/SimulatorTheme.php';
|
|
|
|
class AntadisSimulator extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'antadissimulator';
|
|
$this->tab = 'front_office_features';
|
|
$this->version = '0.1';
|
|
$this->author = 'antadis';
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Simulator');
|
|
$this->description = $this->l('Simulator and theme');
|
|
|
|
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
|
|
|
|
$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
// Call install parent method
|
|
if (!parent::install()) {
|
|
return false;
|
|
}
|
|
|
|
// Menu
|
|
if (!$this->installTab('AdminCatalog', 'AdminAntadisSimulator', 'Simulator')) {
|
|
return false;
|
|
}
|
|
|
|
// Controllers
|
|
if (!$this->installTab('AdminCatalog', 'AdminAntadisSimulatorTheme', 'SimulatorTheme', 0) ||
|
|
!$this->installTab('AdminCatalog', 'AdminAntadisSimulatorDetail', 'SimulatorDetail', 0)) {
|
|
return false;
|
|
}
|
|
|
|
// Hook
|
|
if (!$this->registerHook('Header') ||
|
|
!$this->registerHook('displayAdminProductsExtra') ||
|
|
!$this->registerHook('displayProductBloc')) {
|
|
return false;
|
|
}
|
|
|
|
// All went well!
|
|
return true;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
// Call uninstall parent method
|
|
if (!parent::uninstall()) {
|
|
return false;
|
|
}
|
|
|
|
// Menu
|
|
if (!$this->uninstallTab('AdminAntadisSimulator')) {
|
|
return false;
|
|
}
|
|
|
|
// Hook
|
|
if (!$this->unregisterHook('Header') ||
|
|
!$this->unregisterHook('displayAdminProductsExtra') ||
|
|
!$this->unregisterHook('displayProductBloc')) {
|
|
return false;
|
|
}
|
|
|
|
// All went well!
|
|
return true;
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
$ajax_hook = Tools::getValue('ajax_hook');
|
|
if ($ajax_hook != '') {
|
|
$ajax_method = 'hook'.ucfirst($ajax_hook);
|
|
if (method_exists($this, $ajax_method)) {
|
|
die($this->{$ajax_method}(array()));
|
|
}
|
|
}
|
|
|
|
$controller = $this->getHookController('getContent');
|
|
return $controller->run();
|
|
}
|
|
|
|
|
|
public function installTab($parent, $class_name, $name, $active = 1)
|
|
{
|
|
// Create new admin tab
|
|
$tab = new Tab();
|
|
$tab->id_parent = (int)Tab::getIdFromClassName($parent);
|
|
$tab->name = array();
|
|
foreach (Language::getLanguages(true) as $lang) {
|
|
$tab->name[$lang['id_lang']] = $name;
|
|
$tab->class_name = $class_name;
|
|
$tab->module = $this->name;
|
|
$tab->active = $active;
|
|
return $tab->add();
|
|
}
|
|
}
|
|
|
|
public function uninstallTab($class_name)
|
|
{
|
|
// Retrieve Tab ID
|
|
$id_tab = (int)Tab::getIdFromClassName($class_name);
|
|
|
|
// Load tab
|
|
$tab = new Tab((int)$id_tab);
|
|
|
|
// Delete it
|
|
return $tab->delete();
|
|
}
|
|
|
|
public function getHookController($hook_name)
|
|
{
|
|
// Include the controller file
|
|
require_once(dirname(__FILE__).'/controllers/hook/'. $hook_name.'.php');
|
|
|
|
// Build dynamically the controller name
|
|
$controller_name = $this->name.$hook_name.'Controller';
|
|
|
|
// Instantiate controller
|
|
$controller = new $controller_name($this, __FILE__, $this->_path);
|
|
|
|
// Return the controller
|
|
return $controller;
|
|
}
|
|
|
|
public function hookHeader($params)
|
|
{
|
|
if($this->context->controller instanceof ProductController) {
|
|
$this->context->controller->addCSS($this->_path.'views/css/simulate.css');
|
|
$this->context->controller->addJS($this->_path.'views/js/utils.js');
|
|
|
|
$this->context->controller->addCSS($this->_path.'views/colorpicker/jquery.simplecolorpicker.css');
|
|
$this->context->controller->addJS($this->_path.'views/colorpicker/jquery.simplecolorpicker.js');
|
|
|
|
// Get id_product and simulator to include js
|
|
$id_product = (int)Tools::getValue('id_product');
|
|
$id_simulator = Simulator::getFromProduct($id_product);
|
|
$id_simulator_theme = SimulatorTheme::getFromProduct($id_product);
|
|
$simulator = new Simulator($id_simulator);
|
|
$simutatorTheme = new SimulatorTheme($id_simulator_theme);
|
|
$themeName = $simutatorTheme->name;
|
|
$themeImagePath = _PS_BASE_URL_.'/themes/simulation/'.$simulator->code.'/'.$themeName;
|
|
$this->context->smarty->assign(array(
|
|
'simulatorCode' => $simulator->code,
|
|
'simulatorName' => $simulator->name,
|
|
'themeName' => $themeName,
|
|
'themeImagePath' => $themeImagePath,
|
|
));
|
|
$this->context->controller->addJS($this->_path.'views/js/'.$simulator->code.'.js');
|
|
}
|
|
}
|
|
|
|
public function hookDisplayAdminProductsExtra($params)
|
|
{
|
|
$controller = $this->getHookController('displayAdminProductsExtra');
|
|
return $controller->run();
|
|
}
|
|
|
|
public function hookDisplayProductBloc($params)
|
|
{
|
|
$controller = $this->getHookController('displayProductBloc');
|
|
return $controller->run();
|
|
}
|
|
}
|