brys Posted August 28, 2019 Share Posted August 28, 2019 (edited) In my module Prestashop 1.7.5 I want to override the product list view in the admin panel, and more precisely, I want to add an additional action of my controller for each of the products on the list. Where there are actions View, Delete duplicate. I copied src/PrestaShopBundle/Resources/views/Admin/Product/CatalogPage/Lists/list.html.twig kopiując to mymodule modules/mymodule/views/PrestaShop/Admin/Product/CatalogPage/Lists/list.html.twig And how do I add my action stick to my controller now? I see that there is such a code, but I do not know how to insert a link to the action in my controller, preferably with the id_product {% set buttons_action = [ { "href": product.preview_url|default('#'), "target": "_blank", "icon": "remove_red_eye", "label": "Preview"|trans({}, 'Admin.Actions') } ] %} {% set buttons_action = buttons_action|merge([ { "onclick": "unitProductAction(this, 'duplicate');", "icon": "content_copy", "label": "Duplicate"|trans({}, 'Admin.Actions') } ]) %} {% set buttons_action = buttons_action|merge([ { "onclick": "unitProductAction(this, 'delete');", "icon": "delete", "label": "Delete"|trans({}, 'Admin.Actions') } ]) %} Edited August 28, 2019 by brys (see edit history) Link to comment Share on other sites More sharing options...
Rolige Posted August 28, 2019 Share Posted August 28, 2019 Hello: For adding and extra action in AdminController of your module you do not need to touch any tpl or twig file. Just need some pieces of code in your AdminController.php file: $this->addRowAction('newaction'); then public function displayNewactionLink($token = null, $id = null) { $this->context->smarty->assign(array( 'href' => self::$currentIndex.'&'.$this->identifier.'='.(int)$id .'&action=newaction&token='.($token != null ? $token : $this->token), 'action' => $this->l('New Action'), 'icon' => 'icon-mail-forward', )); return $this->context->smarty->fetch($this->module->getLocalPath().'views/templates/admin/list_action_forward.tpl'); } Just copy the same code of the edit button action to your file list_action_forward.tpl and modifiy it. finally public function processNewaction() { //do something } Regards 1 Link to comment Share on other sites More sharing options...
brys Posted August 28, 2019 Author Share Posted August 28, 2019 1 hour ago, Rolige said: Hello: For adding and extra action in AdminController of your module you do not need to touch any tpl or twig file. Just need some pieces of code in your AdminController.php file: $this->addRowAction('newaction'); then public function displayNewactionLink($token = null, $id = null) { $this->context->smarty->assign(array( 'href' => self::$currentIndex.'&'.$this->identifier.'='.(int)$id .'&action=newaction&token='.($token != null ? $token : $this->token), 'action' => $this->l('New Action'), 'icon' => 'icon-mail-forward', )); return $this->context->smarty->fetch($this->module->getLocalPath().'views/templates/admin/list_action_forward.tpl'); } Just copy the same code of the edit button action to your file list_action_forward.tpl and modifiy it. finally public function processNewaction() { //do something } Regards I have to insert it directly in the file /controllers/admin/AdminProductsController.php ? I send screen where I want to put this action. It's about the list of products in prestashop 1.7.5 in the admin panel Link to comment Share on other sites More sharing options...
Rolige Posted August 29, 2019 Share Posted August 29, 2019 22 hours ago, brys said: I have to insert it directly in the file /controllers/admin/AdminProductsController.php ? I send screen where I want to put this action. It's about the list of products in prestashop 1.7.5 in the admin panel Hello: Yes, that the pace where the action will be showed. And not, you should never touch controllers/admin/AdminProductsController.php, you should insert code on your own ModuleAdminController class. A recommend you to Look for a tutorial of how to implement your own AdminController class before continue. Link to comment Share on other sites More sharing options...
brys Posted August 29, 2019 Author Share Posted August 29, 2019 2 hours ago, Rolige said: Hello: Yes, that the pace where the action will be showed. And not, you should never touch controllers/admin/AdminProductsController.php, you should insert code on your own ModuleAdminController class. A recommend you to Look for a tutorial of how to implement your own AdminController class before continue. Currently, I really need how to change the "href" parameter in list.html.twig to point to my controller in the code {% set buttons_action = [ { "href": product.preview_url | default ('#'), "target": "_blank", "icon": "remove_red_eye", "label": "Preview" | trans ({}, 'Admin.Actions')} ] %} My controller sample: /admin/index.php?controller=AdminMyControlerSample&token=c21c6d1372a6950e4cb9ef9e01aa7124 and action name: "hello" Link to comment Share on other sites More sharing options...
Fabuloops Posted January 8, 2020 Share Posted January 8, 2020 All explanations here : https://devdocs.prestashop.com/1.7/modules/concepts/templating/admin-views/ Link to comment Share on other sites More sharing options...
Kogkalidis Posted June 21, 2020 Share Posted June 21, 2020 Guys I am struggling in the same path but with suppliers controller (right now on 1.7.7.0 beta is also included in symfony eco-system). I have extended the old so called rowAction (like you comment above) [I just did it by comparing the core symfony code and then verified by your comment]. I have altered the supplier table, adding fields. I save the fields, retrieve the values when I click on the respective row action. BUT I also need some extra stuff (which is the serious troubles I have to solve). It's like supplier_extra id_supplier_extra id_supplier ... (more columns) And I want to click on a separate row action like "get the supplier_extra data with supplier id (old Tools::getValue('id_supplier'))" where it will redirect to a separate environment (class/admin controller) to add rows to the supplier, delete or update them as well. With no success. PS: I can make it the old way (in completely new tab on the left menu) but this is not best practice from UX perspective. I am looking to implement it over the genuine supplier stuff. 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