Page 1 of 1

Hook to add details into admin customers

Posted: Sun Apr 07, 2024 5:46 pm
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.

Re: Hook to add details into admin customers

Posted: Sun Apr 07, 2024 6:28 pm
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));
        },
      ],
    ]);
    

Re: Hook to add details into admin customers

Posted: Mon Apr 08, 2024 7:36 am
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.

Re: Hook to add details into admin customers

Posted: Mon Apr 08, 2024 8:18 am
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.

Re: Hook to add details into admin customers

Posted: Mon Apr 08, 2024 10:11 am
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.

Re: Hook to add details into admin customers

Posted: Mon Apr 08, 2024 11:28 am
by ecartz
Try running that SQL in phpMyAdmin

Re: Hook to add details into admin customers

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

Code: Select all

('id ', $row)
should be:

Code: Select all

('id', $row)

Re: Hook to add details into admin customers

Posted: Mon Apr 08, 2024 11:39 am
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.