skorupa Posted January 31, 2013 Share Posted January 31, 2013 Hi, I try to build plugin that adds new tab to product add/edit in back office. Found out that it is quite easy with displayAdminProductsExtra hook: public function install() { if(parent::install() == false || !$this->registerHook('displayAdminProductsExtra')) return false; return true; } and my function: public function hookDisplayAdminProductsExtra($params) { // ... some stuff return 'output'; } But unfortunately function that call this hook doesn't give us proper product info (AdminProductsController.php:4098): public function initFormModules($obj) { $id_module = Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = \''.pSQL($this->tab_display_module).'\''); $this->tpl_form_vars['custom_form'] = Hook::exec('displayAdminProductsExtra', array(), (int)$id_module); } My solution for this problem is overrite: public function initFormModules($obj) { $id_module = Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = \''.pSQL($this->tab_display_module).'\''); $this->tpl_form_vars['custom_form'] = Hook::exec('displayAdminProductsExtra', array('obj' => $obj), (int)$id_module); } But my main concern is why it is not default functionality. Is there some disadvanatages to it, or just oversign. Link to comment Share on other sites More sharing options...
axelmdp Posted March 8, 2013 Share Posted March 8, 2013 (edited) Hello skorupa. I hope is not too late for you. I have a solution for you: public function hookDisplayAdminProductsExtra($params) { $id_product = Tools::getValue('id_product'); $product = new Product($id_product); //.. return 'output'; } I hope this would be helpful for you (or anyone else reading this topic ) Best Regards, Axel ------------------ Check this cool modules (must have) : MultiTabsForProducts LoginAsCustomer for PS1.5 Cart Details Edited April 3, 2013 by axelmdp (see edit history) 3 Link to comment Share on other sites More sharing options...
vekia Posted March 8, 2013 Share Posted March 8, 2013 Hello skorupa. I hope is not too late for you. I have a solution for you: public function hookDisplayAdminProductsExtra($params) { $id_product = Tools::getValue('id_product'); $product = new Product($id_product); //.. return 'output'; } I hope this would be helpful for you (or anyone else reading this topic ) Best Regards, thanks for sharing the solution Link to comment Share on other sites More sharing options...
Mr S Posted March 10, 2013 Share Posted March 10, 2013 (edited) Google + prestashop forums = problem solved Thanks just what i was looking for Edited March 10, 2013 by HA!*!*Y (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2013 Share Posted March 10, 2013 i marked this topic as solved for other forum members regards Link to comment Share on other sites More sharing options...
skorupa Posted March 22, 2013 Author Share Posted March 22, 2013 @Axelmdp Your solution was very good, and I will use it in future code. Thanks Link to comment Share on other sites More sharing options...
sadlyblue Posted April 3, 2013 Share Posted April 3, 2013 Hi, After creating the tab, and a form in the tab How do i control where the data is saved, when the buttton "Save" or "save and stay" is pressed? Thanks Pedro Link to comment Share on other sites More sharing options...
axelmdp Posted April 3, 2013 Share Posted April 3, 2013 Hi, After creating the tab, and a form in the tab How do i control where the data is saved, when the buttton "Save" or "save and stay" is pressed? Thanks Pedro Hello Pedro, how are you? You can use the hook "actionAdminProductsControllerSaveAfter" public function hookActionAdminProductsControllerSaveAfter($params) { //Your code... } Of course, don't forget to register and unregister the hook inside the install and uninstall methods, respectively. Bests Regards, Axel ------------------ Check this cool modules (must have) : MultiTabsForProducts LoginAsCustomer for PS1.5 Cart Details Link to comment Share on other sites More sharing options...
sadlyblue Posted April 3, 2013 Share Posted April 3, 2013 Thanks axelmdp. Just one last thing. Say i have a input text with the name "desc1". How can i get the result inside that hook? Is it as simple as $params[desc1]? My experience with hooks with "action" is little. And it's hard to get an output to see the result. Thanks again. Link to comment Share on other sites More sharing options...
axelmdp Posted April 3, 2013 Share Posted April 3, 2013 Thanks again. You're welcome Pedro. Well, some considerations about the mentioned hook: 1 - You can get all parameters that you have put into the tab as "input" in this way: $myVar = Tools::getValue('INPUT_NAME'); 2 - You can get the product object in this way: $product = $params['return']; 3 - You should check if the save operation was sucessfull during the request processing. To do that, you could put your code inside this condition: if ($product AND Tools::getValue('MY_TAB_WAS_LOADED') == '1' AND $product->id) { //Put your code here } Where "MY_TAB_WAS_LOADED" it would be a field that you also should had added as input on the tab html code: <input name="MY_TAB_WAS_LOADED" type="hidden" value="1"> I'd recommend this strategy in order to ensure that your tab was properly loaded. Take in account that the loading tabs process is done via ajax, and it is possible that the user presses the save button when your tab has not even been loaded. I hope this was useful for you and the developers community. If you like it, click on the button. If you love it, make me a donation. I'd really appreciate it. Best Regards, Axel ------------------ Check this cool modules (must have) : MultiTabsForProducts LoginAsCustomer for PS1.5 Cart Details Link to comment Share on other sites More sharing options...
lgldemon Posted December 24, 2015 Share Posted December 24, 2015 Where i can add image upload button in thems in prestashop backoffice Link to comment Share on other sites More sharing options...
Soullivaneuh Posted February 29, 2016 Share Posted February 29, 2016 (edited) thanks for sharing the solution This is more a workaround than a solution IMO because the SQL logic for retrieve the product is executed twice AFAIK. Why the product object is not passed directly on the parameters array? @skorupa override make sense, it should be integrated on the core. EDIT: I made a PR about that: https://github.com/PrestaShop/PrestaShop/pull/5095 Edited February 29, 2016 by Soullivaneuh (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