Hook to add details into admin customers

Open to all! Ask other shopowners for help.
Post Reply
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Hook to add details into admin customers

Post by 14Steve14 »

Phoenix 1.0.9.0 PHP8.1

I have created a hook which adds additional information on the customers page. I can get it to show the customers phone number, mobile and business name if there is one, but I cannot get it to show the customers ID. The hook is based on a adjusted copy of another that adds information into the orders table, and that works.

The code below shows the heading but the data next to each customer is empty.

This is the code that I have used.

Code: Select all

class hook_admin_customers_extra_details {

  public function listen_constructPaginator() {
    $pos = 2;
    
    array_splice($GLOBALS['table_definition']['columns'], $pos, 0, [
      [
        'name' => 'Mobile',
        'function' => function (&$row) {
          return strip_tags($row['customers_fax']);
        },
      ],
    ]);
    
    array_splice($GLOBALS['table_definition']['columns'], $pos, 0, [
      [
        'name' => 'Phone',
        'function' => function (&$row) {
          return strip_tags($row['customers_telephone']);
        },
      ],
    ]);
    
    array_splice($GLOBALS['table_definition']['columns'], $pos, 0, [
      [
        'name' => 'Company name',
        'function' => function (&$row) {
          return strip_tags($row['entry_company']);
        },
      ],
    ]);
    
    array_splice($GLOBALS['table_definition']['columns'], $pos, 0, [
      [
        'name' => 'Cust No',
        'function' => function (&$row) {
          return strip_tags($row['customers_id ']);
        },
      ],
    ]);
  }
  
}
Why would some work and not the customers ID. Is it a case that the code as changed in a newer version.


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Hook to add details into admin customers

Post by ecartz »

Code: Select all

    array_splice($GLOBALS['table_definition']['columns'], 2, 0, [
      [
        'name' => 'Cust No',
        'function' => function (&$row) {
          return strip_tags($GLOBALS['customer_data']->get('id', $row));
        },
      ],
      [
        'name' => 'Company name',
        'function' => function (&$row) {
          return strip_tags($GLOBALS['customer_data']->get('company', $row));
        },
      ],
      [
        'name' => 'Phone',
        'function' => function (&$row) {
          return strip_tags($GLOBALS['customer_data']->get('telephone', $row));
        },
      ],
      [
        'name' => 'Mobile',
        'function' => function (&$row) {
          return strip_tags($GLOBALS['customer_data']->get('fax', $row));
        },
      ],
    ]);
    
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Hook to add details into admin customers

Post by 14Steve14 »

@ecartz . Thanks for that.

When I add your code into the hook, it shows all the data apart from the customers ID, the same as my older code did. I have checked the database and customers ID is there. The customers ID shows correctly where the information was added into the invoice so I take it that the database can read and fetch the ID number.

The database has been upgraded from a 1.0.7.11 version so could this affect the tables or something.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Hook to add details into admin customers

Post by ecartz »

What happens if you put

Code: Select all

die($customers_sql);
at line 119 of admin/customers.php?

Note: this is a debugging step. It won't fix things (it will break them more thoroughly). The result might make it clearer what is happening.
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Hook to add details into admin customers

Post by 14Steve14 »

The result of that shows the following
SELECT ci.*, co.*, ab.*, c.*, c.customers_id AS id, c.customers_firstname AS firstname, c.customers_lastname AS lastname, c.customers_email_address AS email_address, ab.entry_country_id AS country_id, ci.customers_info_date_account_created AS date_account_created, ci.customers_info_date_account_last_modified AS date_account_last_modified, ci.customers_info_date_of_last_logon AS date_last_logon, ci.customers_info_number_of_logons AS number_of_logons FROM customers c LEFT JOIN address_book ab ON c.customers_id = ab.customers_id AND c.customers_default_address_id = ab.address_book_id LEFT JOIN countries co ON ab.entry_country_id = co.countries_id INNER JOIN customers_info ci ON c.customers_id = ci.customers_info_id ORDER BY c.customers_id DESC
Looking at that ID does seem to be there.

I have just created a new customer. The customer shows in the customers list and everything seems to be stored in the database. The next customer ID was added but it does not show in the column that is added in the customers page using this hook.

If I add the following into the customers page where rthe other table data is created the customers ID does not populate.

Code: Select all

[
          'name' => TABLE_HEADING_ID,
          'function' => function (&$row) use ($customer_data) {
              return $customer_data->get('id ', $row);
            },
        ],
Can I assume that maybe during the upgrade of the database something didnt get done relating to the customers table, or data.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Hook to add details into admin customers

Post by ecartz »

Try running that SQL in phpMyAdmin
raiwa
Certified Developer
Posts: 1641
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Hook to add details into admin customers

Post by raiwa »

there is space after id:

Code: Select all

('id ', $row)
should be:

Code: Select all

('id', $row)
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Hook to add details into admin customers

Post by 14Steve14 »

raiwa wrote: Mon Apr 08, 2024 11:28 am there is space after id:

Code: Select all

('id ', $row)
should be:

Code: Select all

('id', $row)
@raiwa You are a star.

I looked after making that change and there were no errors showing in either error logs. Does an extra space really stop the page working without throwing an error, or was I just unlucky. This coding is one big learning curve.


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