Insert column into table displayed in admin/customers.php

Open to all! Ask other shopowners for help.
Post Reply
cut-n-paste
Member
Posts: 28
Joined: Fri Oct 07, 2022 12:20 pm
Phoenix Version:
Has thanked: 2 times
Been thanked: 5 times

Insert column into table displayed in admin/customers.php

Post 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'];
      },
    ];
  }
 }


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4550
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

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

Post 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.
I am not here to build for you.
I am here to build with you. Let's help each other.
cut-n-paste
Member
Posts: 28
Joined: Fri Oct 07, 2022 12:20 pm
Phoenix Version:
Has thanked: 2 times
Been thanked: 5 times

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

Post 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
beerbee
Member
Posts: 48
Joined: Mon Oct 26, 2020 4:56 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 5 times

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

Post by beerbee »

Hi,

Code: Select all

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

Kind regards
Christoph
cut-n-paste
Member
Posts: 28
Joined: Fri Oct 07, 2022 12:20 pm
Phoenix Version:
Has thanked: 2 times
Been thanked: 5 times

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

Post 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!
beerbee
Member
Posts: 48
Joined: Mon Oct 26, 2020 4:56 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 5 times

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

Post by beerbee »

One gets fetched from the orders table, the other one from the customers address book.
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

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

Post 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'];
            },
        ]]);
    }
}


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply