Menu Close
    Hire us Request quote Reading list Switch to dark mode

    How to modify fields list before rendring of an Admin controller in prestashop

    In this blog we are going to learn how to modify fields list  before rendring of an Admin controller in prestashop.

    As we all know in an admin controller to show a render list, it is must to create a fields list. We define the $fields_list variable in the admin controller. In the $fields_list variable, we define all the required things in the render list.

    All the columns defined in the $fields_list variable are shown in the render list.

    Let’s understand the entire process with the help of taking an example of  AdminAddressesController. In the below code you can see how fields list is defined in the AdminAddressesController-

     And renderlist made by the above fields list in AdminAddressesController looks like the below image-

    It is the renderlist rendered by the predefined $fields_list variable in the AdminAddressesController. Now what if you want to add some more columns in this renderlist.

    Prestashop provides a hook in the AdminController.php class through which we can modify the coulums of the renderlist of any admin controller.

    Note :: In the hook $this->controller is the name of the admin controller which fields list you are going to change.

    Using the above hook you can modify the $fields_list of the admin controller’s render list. Lets understand the process with an example-

    We are going to add a column in the AdminAddressesController’s render list which will show the email address of the customer. What you have to do is in your main class of your module you have to define the above hook. Example-

    In the above example we have replaced $this->controller with the admin controller’s name which render list we are going to modify i.e. AdminAddresses . 

    We just have to use the parameters provided in the hook wisely and we can modify the renderlist of the backoffice controller as per our requirements.

    In the above implementation, we have added the email of the customer from _DB_PREFIX_.’customer’ table in the $fields_list of the AdminAddresses controller and you can see in the below image how it is added in the renderlist of the controller-

    So this is how you can modify fields list before rendering of an Admin controller in PrestaShop.

    . . .

    Comments (7)

    Add Your Comment

  • Avi
    How can we use filter key for a ‘Name’ column which contains both first name and last name combined.
    • Sumit
      Currently, In the Hook, you can only filter from one column “firstname” Or “lastname” if you are concatenating “firstname” and “lastname” to combine the name.
      You can not filter with the full name (firstname lastname) if you are adding it from the hook in the list as per my research.
  • Jose Fanjul
    Special thanks man. Here is the unique site when really explain perfect this case. Have a nice day!
  • karlix
    This line $params[‘select’] .= ‘, as customer_email’; shouldn’t start with the comma. Thanks!
    • Sumit
      As in the blog we are modifying (adding column) the list. So we are concatenating our column with
      $params[‘select’] .= ‘, as customer_email’;
      You can use it like this without any issue.
  • Qasim Zubair
    I am trying this on prestashop for hookActionAdminProductsListingFieldsModifier . Product list page , but its not working. Any Idea?
    • sumit
      Please ensure you have registered the hook too.
      As in your case register hook with
      Hope it will help.
  • Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again