simon.bonjean Posted December 3, 2012 Share Posted December 3, 2012 Bonjour, J'essaie de faire une module pour prestashop 1.5 mais je n'arrive pas a surchargé le coeur de prestashop dans mon module. modules/doublecmscontent/override/controller/AdminCmsController.php modules/doublecmscontent/override/classes/CMS.php class CMS extends CMSCore { public $content2; public static $definition = array( 'table' => 'cms', 'primary' => 'id_cms', 'multilang' => true, 'fields' => array( 'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'position' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), // Lang fields 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), 'content2' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), ), ); } Je ne suis pas certain que le code fonctionne mais a l'installation du module il me donne le messages suivant : /httpdocs/classes/module/Module.php(1880) : eval()'d code on line 31 Après ça le fichier CMS.php dans le dossier override racine ressemble à ça : class CMS extends CMSCore { 'table' => 'cms', 'primary' => 'id_cms', 'multilang' => true, 'fields' => array( 'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'position' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), // Lang fields 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), 'content2' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), ), ); } Pourquoi la ligne de déclaration de ma variable a disparue ? Ca fait pareil pour les fonctions. Est-ce que je fait quelque chose de mal ? Quelqu'un sait-il m'aider ? Link to comment Share on other sites More sharing options...
coeos.pro Posted December 3, 2012 Share Posted December 3, 2012 essaye déjà de changer modules/doublecmscontent/override/controller/AdminCmsController.php par modules/doublecmscontent/override/controller/admin/AdminCmsController.php Link to comment Share on other sites More sharing options...
simon.bonjean Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) C'est effectivement ce qu'avais fait ... (J'ai mal recopié le chemin) J'ai trouvé une solution temporaire mais j'aimerai utiliser la fonction native de prestashop public function installLibs() { foreach ($this->_classes_add as $class) { $class = $class . '.php'; if (!is_dir(_PS_CLASS_DIR_ . $this->name)) mkdir(_PS_CLASS_DIR_ . $this->name); if (file_exists(_PS_CLASS_DIR_ . $class)) { if (!is_dir(_PS_CLASS_DIR_ . $class)) mkdir(_PS_CLASS_DIR_ . $class, 0777, true); copy(_PS_CLASS_DIR_ . '/classes/' . $class, $this->getLocalPath() . 'libs/backup/' . $class); } copy($this->getLocalPath() . 'libs/classes/' . $class, _PS_CLASS_DIR_ . $this->name . '/' . $class); } foreach ($this->_classes_override as $class) { $class = $class . '.php'; if (file_exists(_PS_OVERRIDE_DIR_ . 'classes/'. $class)) { if (!is_dir($this->getLocalPath() . 'libs/backup/override/')) mkdir($this->getLocalPath() . 'libs/backup/override', 0777, true); copy(_PS_OVERRIDE_DIR_ . 'classes/' . $class, $this->getLocalPath() . 'libs/backup/override/' . $class); } copy($this->getLocalPath() . 'libs/override/classes/' . $class, _PS_OVERRIDE_DIR_ . 'classes/' . $class); } foreach ($this->_controller_override_front as $class) { $class = $class . '.php'; if (file_exists(_PS_OVERRIDE_DIR_ . 'controllers/front/'. $class)) { if (!is_dir($this->getLocalPath() . 'libs/backup/override/controllers/front/')) mkdir($this->getLocalPath() . 'libs/backup/override/controllers/front', 0777, true); copy(_PS_OVERRIDE_DIR_ . 'controllers/front/' . $class, $this->getLocalPath() . 'libs/backup/override/controllers/front/' . $class); } copy($this->getLocalPath() . 'libs/override/controllers/front/' . $class, _PS_OVERRIDE_DIR_ . 'controller/front/' . $class); } foreach ($this->_controller_override_admin as $class) { $class = $class . '.php'; if (file_exists(_PS_OVERRIDE_DIR_ . 'controllers/admin/'. $class)) { if (!is_dir( $this->getLocalPath() . 'libs/backup/override/controllers/admin/')) mkdir( $this->getLocalPath() . 'libs/backup/override/controllers/admin', 0777, true); copy(_PS_OVERRIDE_DIR_ . 'controllers/admin/' . $class, $this->getLocalPath() . 'libs/backup/override/controllers/admin/' . $class); } copy($this->getLocalPath() . 'libs/override/controllers/admin/' . $class, _PS_OVERRIDE_DIR_ . 'controllers/admin/' . $class); } Autoload::getInstance()->generateIndex(); return true; } class PdwDoubleCMSContent extends PdwModule { public function __construct() { $this->_controller_override_admin = array('AdminCmsController'); $this->_classes_override = array('CMS'); } } Edited December 3, 2012 by simon.bonjean (see edit history) Link to comment Share on other sites More sharing options...
simon.bonjean Posted December 3, 2012 Author Share Posted December 3, 2012 if(_PS_MODE_DEV_) { Module::getInstanceByName('monmodule')->installLibs(); } J'ajoute ceci dans config.inc.php histoire pas me faire chier en dev. Link to comment Share on other sites More sharing options...
coeos.pro Posted December 3, 2012 Share Posted December 3, 2012 mais quand tu installe ton module, tu as un message d'erreur ou non ? tu as vidé le fichier AdminCmsController.php de l'override avant d'installer le module ? Link to comment Share on other sites More sharing options...
simon.bonjean Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) Oui j'ai même supprimé les fichier présent dans le dossier override avant d'installé mais rien a faire. Quand je passe par l'installation normal du module il me dit jusque que ça n'a pas marché. Mais j'ai fais un petit script qui désinstalle et installe mon module rapidement. Très pratique pour testé l'installation d'un module. Et là j'ai un fatal error. La classe Module.php fait un eval du code de ma surcharge de classe et forcément sans les déclarations de mes variables et ben ça marche pas. /httpdocs/classes/module/Module.php(1880) : eval()'d code on line 31 Mon script d'install rapide : <?php // a ne pas laisser en production bien évidement define('_PS_ADMIN_DIR_', getcwd()); require(dirname(dirname(__FILE__)).'/config/config.inc.php'); $modules = array('monmodule'); foreach($modules as $module) { echo "<h1>" . $module ."</h1>"; $module_instance = Module::getInstanceByName($module); if(Module::isInstalled($module)) { echo "<h3>" . $module ." is installed</h3>"; if($module_instance->uninstall()) { echo "<h2>uninstall $module Success</h2>"; } } if($module_instance->install()) { echo "<h2>install $module Success</h2>"; } else { foreach($module_instance->getErrors() as $error) { echo "<h3 style='color: red'> $error </h3>"; } echo "<h3 style='color: red'> unable to install</h3>"; } } Edited December 3, 2012 by simon.bonjean (see edit history) Link to comment Share on other sites More sharing options...
coeos.pro Posted December 3, 2012 Share Posted December 3, 2012 peux tu m'envoyer ton override que je vois ce qui peux clocher ? Link to comment Share on other sites More sharing options...
simon.bonjean Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) monmodule/override/classes/CMS.php <?php class CMS extends CMSCore { public $content2; public static $definition = array( 'table' => 'cms', 'primary' => 'id_cms', 'multilang' => true, 'fields' => array( 'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'position' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), // Lang fields 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), 'content2' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), ), ); } monmodule/override/controllers/admin/AdminCmsController.php <?php class AdminCmsController extends AdminCmsControllerCore { public function renderForm() { $this->display = 'edit'; $this->toolbar_btn['save-and-preview'] = array( 'href' => '#', 'desc' => $this->l('Save and preview') ); $this->initToolbar(); if (!$this->loadObject(true)) return; $categories = CMSCategory::getCategories($this->context->language->id, false); $html_categories = CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($this->object, 'id_cms_category'), 1); $this->fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('CMS Page'), 'image' => '../img/admin/tab-categories.gif' ), 'input' => array( // custom template array( 'type' => 'select_category', 'label' => $this->l('CMS Category'), 'name' => 'id_cms_category', 'options' => array( 'html' => $html_categories, ), ), array( 'type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'id' => 'name', // for copy2friendlyUrl compatibility 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 50 ), array( 'type' => 'text', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 70 ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 70, 'desc' => $this->l('To add "tags" click in the field, write something, then press "Enter"') ), array( 'type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true, 'hint' => $this->l('Only letters and the minus (-) character are allowed') ), array( 'type' => 'textarea', 'label' => $this->l('Page content'), 'name' => 'content', 'autoload_rte' => true, 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'radio', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array( 'type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso', ); } $this->tpl_form_vars = array( 'active' => $this->object->active ); $this->fields_form['input'][] = array( 'type' => 'textarea', 'label' => $this->l('Page content 2'), 'name' => 'content2', 'autoload_rte' => true, 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ); return AdminController::renderForm(); } } Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_FUNCTION in /****/httpdocs/classes/module/Module.php(1880) : eval()'d code on line 15 Unable to install override: Class CMSOverrideOriginal does not exist Résultat httpdocs/override/classe/CMS.php : <?php class CMS extends CMSCore { 'table' => 'cms', 'primary' => 'id_cms', 'multilang' => true, 'fields' => array( 'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'position' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), // Lang fields 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), 'content2' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), ), ); } Résultat httpdocs/override/controllers/admin/AdminCmsController.php : <?php /** 2007-2012 PrestaShop .... .... */ class AdminCmsController extends AdminCmsControllerCore { Edited December 3, 2012 by simon.bonjean (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now