Jump to content

Override the product list view in the admin panel,


Recommended Posts

 

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 by brys (see edit history)
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

products.png

Link to comment
Share on other sites

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

products.png

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

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

  • 4 months later...
  • 5 months later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...