Jump to content

[PS 1.7][Problem] - Define personal callback in custom modules


Recommended Posts

I'm writing a custom module for prestaShop.
I was able to correctly display a new field in the list of customers in the BackEnd section.

Now I would need to insert a callback for a specific field in this table but when I try to use it I get an error.

PrestaShop tells me that the callback function called up is not available in the AdminController.

Attached to this message is the complete code of my module.

The callback i want to use is :
 

public function printAsiStatusIcon($value, $customer)
    {
        return '<a class="list-action-enable '.($value ? 'action-enabled' : 'action-disabled').'" href="index.php?'.htmlspecialchars('tab=AdminCustomers&id_customer='
                .(int)$customer['id_customer'].'&changeAsiStatus&token='.Tools::getAdminTokenLite('AdminCustomers')).'">
				'.($value ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>').
            '</a>';
    }

 

and called in this section of crsociasi.php :

 

foreach ($params['fields'] as $key => $value){
            if ($key!='email'){
                $newParam[$key]=$value;
            }
            else{
                $newParam[$key]=$value;
                $newParam['cardAsi'] = array(
                    'title' => 'cardAsi',
                    'align' => 'center',
                    'search' => true,
                    'havingFilter' => true,
                    'filter_key' => 'asi!cardAsi'
                );
                $newParam['statoAsi'] = array(
                    'title' => 'Stato Asi',
                    'align' => 'center',
                    'callback' => 'printAsiStatusIcon'
                );
            }
        }
        $params['fields']=$newParam;

The error i receive from PS is :
 

Quote

Warning alla linea 335 nel file ...............classes/helper/HelperList.php
[2] call_user_func_array() expects parameter 1 to be a valid callback, class 'AdminCustomersController' does not have a method 'printAsiStatusIcon'

 

 

Can anyone help me?
Thank's in advance

crsociasi.zip

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

  • 1 month later...
On 11/5/2018 at 2:32 PM, lemoeb said:

I'm writing a custom module for prestaShop.
I was able to correctly display a new field in the list of customers in the BackEnd section.

Now I would need to insert a callback for a specific field in this table but when I try to use it I get an error.

PrestaShop tells me that the callback function called up is not available in the AdminController.

Attached to this message is the complete code of my module.

The callback i want to use is :
 


public function printAsiStatusIcon($value, $customer)
    {
        return '<a class="list-action-enable '.($value ? 'action-enabled' : 'action-disabled').'" href="index.php?'.htmlspecialchars('tab=AdminCustomers&id_customer='
                .(int)$customer['id_customer'].'&changeAsiStatus&token='.Tools::getAdminTokenLite('AdminCustomers')).'">
				'.($value ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>').
            '</a>';
    }

 

and called in this section of crsociasi.php :

 


foreach ($params['fields'] as $key => $value){
            if ($key!='email'){
                $newParam[$key]=$value;
            }
            else{
                $newParam[$key]=$value;
                $newParam['cardAsi'] = array(
                    'title' => 'cardAsi',
                    'align' => 'center',
                    'search' => true,
                    'havingFilter' => true,
                    'filter_key' => 'asi!cardAsi'
                );
                $newParam['statoAsi'] = array(
                    'title' => 'Stato Asi',
                    'align' => 'center',
                    'callback' => 'printAsiStatusIcon'
                );
            }
        }
        $params['fields']=$newParam;

The error i receive from PS is :
 

 

 

Can anyone help me?
Thank's in advance

crsociasi.zip

 

Same problem.... any help guys?

Link to comment
Share on other sites

  • 2 years later...

I believe you have to also specify the callback object.

$newParam['statoAsi'] = array(
      'title' => 'Stato Asi',
      'align' => 'center',
      'callback' => 'printAsiStatusIcon',
      'callback_object => $this
);

Something like that.

What I'm wondering is how parameters are sent to it.
I guess it just receives the value that correlates with it from the $db SELECTED results.

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

  • 9 months later...

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