Add Custom Row action in Prestashop ModuleAdminController

7.5k Views Asked by At

I want to add a download button for each row in moduleadmincontroller helper.

I tried to add it by using the following code on RenderList function. But it is not working.

$this->addRowAction('download');

Kindly let me know if I can add custom action for each row and how to process it.

1

There are 1 best solutions below

2
On BEST ANSWER

as you know the actions is the default array that have default value array('view', 'edit', 'delete', 'duplicate'); and you can use this but if you want add new action you should use some function.for example you can go to your_prestashop/controllers/admin/AdminRequestSqlController.php this class add new action with 'export' name

          $this->addRowAction('export');

then for create link for this action it is using the displayExportLink() function as you can see in bellow code

         public function displayExportLink($token, $id)
{
    $tpl = $this->createTemplate('list_action_export.tpl');

    $tpl->assign(array(
        'href' => self::$currentIndex.'&token='.$this->token.'&
                     '.$this->identifier.'='.$id.'&export'.$this->table.'=1',
            'action' => $this->l('Export')
    ));

    return $tpl->fetch();
}

and then you can get your new action with the initProcess() function or initcontent() function and do something lik download

public function initProcess()
{
    parent::initProcess();
    if (Tools::getValue('export'.$this->table))
    {
        $this->display = 'export';
        $this->action = 'export';
    }
}