Jump to content

Get current row ID or any current information from list of data in Admin controller List


Recommended Posts

Hello, 

I create a new module.

I create a custom admin controller to display a list of data, i create new query and the data is displayed correctly in the page.

Then I created a custom button, but when i click in the button the $ID variable to get the current row is null

how can I retrieve information from the current row of my table when the user clicks on the button

I do many research but the documentation of prestashop is  limited ! 

The columns fields definition --> It's OK , data is diplayed :  

 $this->fields_list = [
            'id_customer' => [
                'title' => $this->module->l('ID Revendeur'), //Titre
                'align' => 'center', // Alignement
                'class' => 'fixed-width-xs' //classe css de l'élément
            ],
            'code_revendeur' => [
                'title' => $this->module->l('Code Revendeur'),
                'align' => 'left',
                'class' => 'fixed-width-xs'
            ],
            'phone' => [
                'title' => $this->module->l('Téléphone'),
                'align' => 'left',
                'class' => 'fixed-width-xs'
            ],
            'firstname' => [
                'title' => $this->module->l('Prénom'),
                'align' => 'left',
                'class' => 'fixed-width-xs'
            ],
            'lastname' => [
                'title' => $this->module->l('Nom'),
                'align' => 'left',
                'class' => 'fixed-width-xs'
            ],
            'email' => [
                'title' => $this->module->l('E-mail'),
                'align' => 'left',
                'class' => 'fixed-width-xs'
            ]
        ];

  The definition of mu custom button 

    public function renderList() {

        $this->addRowAction('newaction');

        return parent::renderList();
    }

Display the button in my table data -> it's OK, But the  $id and $name vars are null, only $token is with data  

    public function displayNewactionLink($token, $id, $name)
    {
        
        $this->context->smarty->assign(array(
            'href' => self::$currentIndex.'&'.$this->identifier.'='.(int)$id
                .'&action=newaction&token='.($token != null ? $token : $this->token),
            'action' => $this->l('Payer la commission du revendeur'),
            'icon' => 'icon-mail-forward',
        ));

        return $this->context->smarty->fetch($this->module->getLocalPath().'views/templates/admin/list_action_payer.tpl');
    }

process action methode : 

    public function processNewaction() {


        // do actions
        
    }

 

when i debug my code, the methode processNewaction is called, but I have no information about the row of the table that the user has selected.

 

Thanks for you 

Edited by Slayem (see edit history)
Link to comment
Share on other sites

  • Slayem changed the title to Get current row ID or any current information from list of data in Admin controller List

 Hello, 

finaly, I find a solution : 

i forgot to declare the right  identifier of my data list 

$this->identifier = 'id_customer';

 in methode "displayNewactionLink($token, $id, $name) ",  the $id param is filled with the id_customer value

Then, when action is called, I find the current values of the row  stored in $this->id_object  var : 

    public function processNewaction() {
         $currentRow =    $this->id_object; 
         //Do My Actions
}

I did this quickly  by copying lots of code from various forums....I don't understand the prestashop framework yet.

I'm really thinking of offering my customers the possibility of migrating to another more flexible and easy-to-use e-commerce framework.

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...