Qvixx Posted October 7, 2013 Share Posted October 7, 2013 (edited) Hi, I need your help again. This is my situation: I need a grouped list of manufacturers with links to their websites. In the backend there should be an additional field called 'Group' where i can define the group (one for each manufacturer). There should also be a field for website to define the manufacturers homepage to link the manufacturer's website. The solution I thought about: Add 2 custom fields to the database and add them to the backend. But maybe there is a better way? Didn't find an existing module for this problem. My Problem: I tried to add my field with this tutorial: http://nemops.com/extending-prestashop-objects/ This is written at Step 2: For now, reach the admin folder, then go to /themes/default/template/controllers/products. In this folder, you’ll see a bunch of tpl files whose names are equal to the name of the sections the product page is divided into. For simplicity, I will choose the first one, informations. Copy informations.tpl and go back to the main folder. Now access override/controllers/admin/templates/. We need to recreate the controller name folder structure inside, in our case, simply products. THe final directory structure is override/controllers/admin/templates/products/. Once you’re done, paste the information template file inside. I just can't find the .tpl file for manufacturer. Surely I look in the manufacturers-folder not in the product-folder The only thing I found is: \adminXXXX\themes\default\template\controllers\manufacturers\helpers\view\view.tpl ... But this seems to be the tpl file for the manufacturer-list not the detailed manufacturer editing-mask. At least I didn't find the correct place to insert my field. Any ideas? Edited October 7, 2013 by Qvixx (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2013 Share Posted October 8, 2013 and what about associations.tpl file where you can select manufacturer? Link to comment Share on other sites More sharing options...
Qvixx Posted October 9, 2013 Author Share Posted October 9, 2013 Hi Vekia, Thank you for your response. It's great to have people like you in a forum who are always there to answer questions! However, as far as I can see, the associations.tpl belongs to the product mask. I want to change this mask: http://abload.de/img/unbenannt5ru2z.png Link to comment Share on other sites More sharing options...
vekia Posted October 9, 2013 Share Posted October 9, 2013 in this case you have to extend object definition here: contorllers/admin/AdminManufacturersController.php public function renderForm() { $this->fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('Manufacturers:'), 'image' => '../img/admin/manufacturers.gif' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 40, 'required' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'textarea', 'label' => $this->l('Short description:'), 'name' => 'short_description', 'lang' => true, 'cols' => 60, 'rows' => 10, 'class' => 'rte', 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'textarea', 'label' => $this->l('Description:'), 'name' => 'description', 'lang' => true, 'cols' => 60, 'rows' => 10, 'class' => 'rte', 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'file', 'label' => $this->l('Logo:'), 'name' => 'logo', 'display_image' => true, 'desc' => $this->l('Upload a manufacturer logo from your computer.') ), array( 'type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'lang' => true, 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'text', 'label' => $this->l('Meta description:'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords:'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Forbidden characters:').' <>;=#{}', 'desc' => $this->l('To add "tags," click inside the field, write something, and then press "Enter."') ), array( 'type' => 'radio', 'label' => $this->l('Enable:'), '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') ) ) ) ) ); Link to comment Share on other sites More sharing options...
Qvixx Posted October 9, 2013 Author Share Posted October 9, 2013 (edited) This thing drives me crazy At least it works almost now My '\override\classes\Manufacturer.php'-file looks like this: <?php Class Manufacturer extends ManufacturerCore { public $website; public function __construct($id_manufacturer = null, $id_lang = null) { self::$definition['fields']['website'] = array('type' => self::TYPE_STRING); parent::__construct($id_manufacturer, $id_lang); } } ?> This file seems to work because my custom field shows up in the front-office. But i have a little question: What is '$id_manufacturer = null, $id_lang = null' standing for? It's more or less copy-pasted from the tutorial but I want to look behind the logic. In the tutorial there were even more parameters like $id_shop or $full ... My '\override\controllers\admin\AdminManufacturersController.php'-file looks like this: <?php Class AdminManufacturersController extends AdminManufacturersControllerCore { public function renderForm() { $this->fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('Manufacturers:'), 'image' => '../img/admin/manufacturers.gif' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 40, 'required' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'text', 'label' => $this->l('Website:'), 'name' => 'website', 'size' => 128, 'required' => false ), array( 'type' => 'textarea', 'label' => $this->l('Short description:'), 'name' => 'short_description', 'lang' => true, 'cols' => 60, 'rows' => 10, 'autoload_rte' => 'rte', //Enable TinyMCE editor for short description 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'textarea', 'label' => $this->l('Description:'), 'name' => 'description', 'lang' => true, 'cols' => 60, 'rows' => 10, 'autoload_rte' => 'rte', //Enable TinyMCE editor for description 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'file', 'label' => $this->l('Logo:'), 'name' => 'logo', 'display_image' => true, 'desc' => $this->l('Upload a manufacturer logo from your computer.') ), array( 'type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'lang' => true, 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'text', 'label' => $this->l('Meta description:'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords:'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Forbidden characters:').' <>;=#{}', 'desc' => $this->l('To add "tags," click inside the field, write something, and then press "Enter."') ), array( 'type' => 'radio', 'label' => $this->l('Enable:'), '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') ) ) ) ) ); if (!($manufacturer = $this->loadObject(true))) return; if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array( 'type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso', ); } $this->fields_form['submit'] = array( 'title' => $this->l('Save '), 'class' => 'button' ); $image = ImageManager::thumbnail(_PS_MANU_IMG_DIR_.'/'.$manufacturer->id.'.jpg', $this->table.'_'.(int)$manufacturer->id.'.'.$this->imageType, 350, $this->imageType, true); $this->fields_value = array( 'image' => $image ? $image : false, 'size' => $image ? filesize(_PS_MANU_IMG_DIR_.'/'.$manufacturer->id.'.jpg') / 1000 : false ); foreach ($this->_languages as $language) { $this->fields_value['short_description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue( $manufacturer, 'short_description', $language['id_lang'] )), ENT_COMPAT, 'UTF-8'); $this->fields_value['description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue( $manufacturer, 'description', $language['id_lang'] )), ENT_COMPAT, 'UTF-8'); } return AdminManufacturersController::renderForm(); } } ?> It seems to override the existing file but it does not work. I get the following error when I trie to edit a manufacturer in the back-office: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65488 bytes) in C:\xampp\htdocs\XXX\classes\Translate.php on line 1809 Today I got this error (didn't change anything): Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\XXXX\classes\ImageManager.php on line 49 Edited October 10, 2013 by Qvixx (see edit history) Link to comment Share on other sites More sharing options...
Qvixx Posted October 16, 2013 Author Share Posted October 16, 2013 Nobody an idea? Link to comment Share on other sites More sharing options...
vekia Posted October 16, 2013 Share Posted October 16, 2013 I get the following error when I trie to edit a manufacturer in the back-office: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65488 bytes) in C:\xampp\htdocs\XXX\classes\Translate.php on line 1809 not-enough free ram memory to run "translate" feature. you need to increase memory limit in php.ini file Today I got this error (didn't change anything): Fatal error: Maximum execution time of 30 seconds exceeded inC:\xampp\htdocs\XXXX\classes\ImageManager.php on line 49 the same as above, but this message is related to script execution time. you can increase limit in .php.ini file too Link to comment Share on other sites More sharing options...
Qvixx Posted October 16, 2013 Author Share Posted October 16, 2013 Hi Vekia, I changed the max_execution_time from 30 to 60. Then memory_limit from 128M to 256M ... But still the same errors. There must be an error in the code but I can't find it. Link to comment Share on other sites More sharing options...
Qvixx Posted October 21, 2013 Author Share Posted October 21, 2013 no one? ... Link to comment Share on other sites More sharing options...
vekia Posted October 21, 2013 Share Posted October 21, 2013 how you changed memory limit? Link to comment Share on other sites More sharing options...
Qvixx Posted October 21, 2013 Author Share Posted October 21, 2013 Changed them in the php.ini to the values written in my last post. I think the code gets into an endless loop. It loads and loads until an error pops up. I just added one field. Shouldn't have a big effect on memory or execution time, should it? Link to comment Share on other sites More sharing options...
NemoPS Posted October 28, 2013 Share Posted October 28, 2013 I know it sounds silly, but it often gets overlooked: have you deleted the class_index.php file inside /cache/? Link to comment Share on other sites More sharing options...
rollwhistler Posted October 30, 2013 Share Posted October 30, 2013 I guess your problem is with return AdminManufacturersController::renderForm(); called this way, the renderForm has no access to $this... The question is how should you call parents parent renderForm :_) Link to comment Share on other sites More sharing options...
Qvixx Posted October 31, 2013 Author Share Posted October 31, 2013 Sorry, I'm new to controllers and things like that. You know how to solve it? If there is an answer in your post I did not get it @Nemo: Sorry did not try it yet. Maybe I can do it this evening. Link to comment Share on other sites More sharing options...
renaud2263 Posted April 10, 2018 Share Posted April 10, 2018 Hi, Did you found the solution ? I have exactly the same problem to add a field "email" in the SupplierController. My override of AdminSupplierController is OK, my override of Supplier class also...but the field don't appear in the form. Of course the column "eamil" has beed added in the supplier DB. I tried to do this to verify the datas in my override class AdminSuppliersController extends AdminSuppliersControllerCore { public function renderForm() { // loads current warehouse if (!($obj = $this->loadObject(true))) { return; } print_r($obj); exit(); And I see the "email" in the object ! Why not in the form ? Link to comment Share on other sites More sharing options...
feinkost Posted April 30, 2018 Share Posted April 30, 2018 Hey Guys, ist there any tutorial for adding custom fields to manufacturer in PrestaShop 1.7 ? Link to comment Share on other sites More sharing options...
renaud2263 Posted May 13, 2018 Share Posted May 13, 2018 If the solution cal help, it's in this post: https://www.prestashop.com/forums/topic/327755-solvedoverriding-is-not-taken-into-account-for-controllersadminadminsupplierscontrollerphp/ The key is: return AdminController::renderForm(); instead of parent::render_form(). 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