Page 1 of 1

Insert column into table displayed in admin/customers.php

Posted: Wed Mar 06, 2024 9:56 am
by cut-n-paste
I have this working hook to add a column to the table displayed in admin/orders.php

Code: Select all

class hook_admin_orders_columnInject {

   public function listen_constructPaginator($paginator) {
    $GLOBALS['table_definition']['columns'][] = [
      'name' => "Company",
      'class' => 'text-right',
      'function' => function ($row) {
        return $row['customers_company'];
      },
    ];
  }
 }
However the following hook for admin/customers.php only adds the column header to the table and not the detail for each line?

Code: Select all

class hook_admin_customers_columnInject {

   public function listen_constructPaginator($paginator) {
    $GLOBALS['table_definition']['columns'][] = [
      'name' => "Company",
      'class' => 'text-right',
      'function' => function ($row) {
        return $row['customers_company'];
      },
    ];
  }
 }

Re: Insert column into table displayed in admin/customers.php

Posted: Wed Mar 06, 2024 10:16 am
by burt
What is saved in the Database for the "customers_company"?
It seems that would be a place to start checking for missing data, as that hook looks Ok.

Re: Insert column into table displayed in admin/customers.php

Posted: Wed Mar 06, 2024 11:40 am
by cut-n-paste
I checked the top 3 customers by clicking on edit and the company names are on that page. In the database the company info is stored in table address_book in column entry_company, baring in mind that almost the same code works for admin/orders.php

Re: Insert column into table displayed in admin/customers.php

Posted: Wed Mar 06, 2024 2:12 pm
by beerbee
Hi,

Code: Select all

return ($row['entry_company']);
for customers.php works for me.

Kind regards
Christoph

Re: Insert column into table displayed in admin/customers.php

Posted: Wed Mar 06, 2024 3:49 pm
by cut-n-paste
Great that make sense and works. Just need to work out why this works for orders when it seems like it shouldn't!

Re: Insert column into table displayed in admin/customers.php

Posted: Wed Mar 06, 2024 3:53 pm
by beerbee
One gets fetched from the orders table, the other one from the customers address book.

Re: Insert column into table displayed in admin/customers.php

Posted: Thu Mar 07, 2024 4:46 am
by Pierre_P
Maybe try order the column in customers page
in this line change the 1 to your liking: array_splice($table_definition['columns'], 1, 0, [[

Code: Select all

    public function listen_constructPaginator($param) {
        global $table_definition;

        array_splice($table_definition['columns'], 1, 0, [[
            'name' => "Company",
            'class' => 'text-center',
            'function' => function ($row) {
                return $row['entry_company'];
            },
        ]]);
    }
}