If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / General Questions / Customer address not appearing in admin>customers - all of a sudden!

Customer address not appearing in admin>customers - all of a sudden!

Started by daxtheman on 13 Dec 2023, 4:59 PM · Views: 2,332

Results 1 to 19 of 19
13 Dec 2023, 4:59 PM
#1
daxtheman avatar

daxtheman

New Zenner

Join Date:
Jun 2023
Location:
UK
Posts:
21
Plugin Contributions:
0

Post #1 by daxtheman

Hi

Can anyone help please?

Running 1.5.8a with PHP8.2

All of a sudden I have a weird problem. Started 7th Dec but site working just fine before that!

In admin>customers (index.php?cmd=customers) the customers list correctly. However, when Edit is pressed the page loads perfectly except for the customer's address. Refresh that page and the address loads.

Meanwhile, in the logs, this error is repeated:

[13-Dec-2023 15:27:13 Europe/London] Request URI: /admin/index.php?cmd=customers&page=1, IP address: 51.185.139.30, Language id 1
#0 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/includes/classes/Customer.php(282): zen_debug_error_handler()
#1 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/includes/classes/Customer.php(29): Customer->load()
#2 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/admin/customers.php(1622): Customer->__construct()
#3 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/admin/index.php(11): require('...')
--> PHP Warning: Undefined array key "address_book_id" in /var/www/vhosts/xxxxxxxco.uk/httpdocs/includes/classes/Customer.php on line 282.

[13-Dec-2023 15:27:13 Europe/London] Request URI: /admin/index.php?cmd=customers&page=1, IP address: 51.185.139.30, Language id 1
#0 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/includes/classes/Customer.php(282): zen_debug_error_handler()
#1 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/includes/classes/Customer.php(29): Customer->load()
#2 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/admin/customers.php(1622): Customer->__construct()
#3 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/admin/index.php(11): require('...')
--> PHP Warning: Undefined array key "zone_id" in /var/www/vhosts/xxxxxx.co.uk/httpdocs/includes/classes/Customer.php on line 282.

[13-Dec-2023 15:27:13 Europe/London] Request URI: /admin/index.php?cmd=customers&page=1, IP address: 51.185.139.30, Language id 1
#0 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/includes/classes/Customer.php(282): zen_debug_error_handler()
#1 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/includes/classes/Customer.php(29): Customer->load()
#2 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/admin/customers.php(1622): Customer->__construct()
#3 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/admin/index.php(11): require('...')
--> PHP Warning: Undefined array key "country_id" in /var/www/vhosts/xxxxxxx.co.uk/httpdocs/includes/classes/Customer.php on line 282.

[13-Dec-2023 15:27:13 Europe/London] Request URI: /admin/index.php?cmd=customers&page=1, IP address: 51.185.139.30, Language id 1
#0 /var/www/vhosts/xxxxxxco.uk/httpdocs/admin/customers.php(1668): zen_debug_error_handler()
#1 /var/www/vhosts/xxxxxxx.co.uk/httpdocs/admin/index.php(11): require('...')
--> PHP Warning: Undefined array key "company" in /var/www/vhosts/xxxxxx.co.uk/httpdocs/admin/customers.php on line 1668.

includes/classes/Customer.php is unaltered from virgin 1.5.8a version.

I am at a loss where to search to see what is triggering this response. There doesn't appear to be any activity in the database on the 6-7th Dec to have caused this change and no site alterations were made (actually on vacation at the time)...

Would appreciate any pointers to solve this one!

14 Dec 2023, 4:31 PM
#2
daxtheman avatar

daxtheman

New Zenner

Join Date:
Jun 2023
Location:
UK
Posts:
21
Plugin Contributions:
0

Post #2 by daxtheman

Me Again!

Okay, so I have noticed something that may be the cause. In the table 'Customers' the 'customers_default_address_id' column has the same for every customer!

I feel that the number there should match the address_book_ id in the address_book table but doesn't.

Can anyone confirm that the assumption above is correct?

If so, can anyone suggest a way to re-connect the two tables so they tally?

Thanks

Dax

14 Dec 2023, 8:26 PM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Post #3 by swguy

Write a script that for each record in the customers table, finds a record in the address book table (with address_book_id >= customers_id) where customers_firstname = entry_firstname and customers_lastname = entry_lastname. This will hopefully fix most of them.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

15 Dec 2023, 10:17 AM
#4
daxtheman avatar

daxtheman

New Zenner

Join Date:
Jun 2023
Location:
UK
Posts:
21
Plugin Contributions:
0

Post #4 by daxtheman

Thanks SWGUY

So I'm thinking:

INSERT INTO customers (customers_default_address_id)
SELECT address_book_id
FROM address_book
WHERE customers_id = customers_id and
customers_firstname = entry_firstname and
customers_lastname = entry_lastname

Since there are 20000 names I don't want to mess this up!

Can anyone confirm the above or suggest better script?

Thanks

15 Dec 2023, 2:06 PM
#5
daxtheman avatar

daxtheman

New Zenner

Join Date:
Jun 2023
Location:
UK
Posts:
21
Plugin Contributions:
0

Post #5 by daxtheman

This is the SQL I finally used.

UPDATE customers INNER JOIN address_book ON customers.customers_id = address_book.customers_id SET customers.customers_default_address_id = address_book.address_book_id
WHERE customers.customers_firstname = address_book.entry_firstname and customers.customers_lastname = address_book.entry_lastname

Hopefully that will be an end to it!

16 Dec 2023, 5:18 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #6 by mc12345678

Well perhaps for existing customers, but what about new ones? Further, figured out why the above was necessary?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

16 Dec 2023, 6:43 PM
#7
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Post #7 by swguy

Good point - it would be worth creating a new (test) storefront account and being sure the customers_default_address_id is set correctly.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

17 Dec 2023, 5:53 PM
#8
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Post #8 by gothstone

following, I suddenly have the same issue and no clue why

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

17 Dec 2023, 6:39 PM
#9
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Post #9 by gothstone

For my site the issue happened sometime between Nov 26th and Dec 13th. The last real change I made was switching from PayPal Pro to the paid version of the Square module, but it can't have been the installation of Square because I did that to my dev site first, and my dev site didn't have the messed up default addresses. I also installed lat's access blocker, but that shouldn't come close to touching the addresses...
just trying to throw out info here in hopes someone figures this out.

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

20 Dec 2023, 7:33 PM
#10
jjone avatar

jjone

New Zenner

Join Date:
Oct 2008
Posts:
10
Plugin Contributions:
1

Post #10 by jjone

This is a zen cart 1.5.8a bug

This is how to test it: first change all customer default address id to a same number with following sql.

UPDATE customers set customers_default_address_id = 10


Now, login to your zen cart admin and goto Customers and click on any customer

after that, open phpMyAdmin and refresh the customers tables

all rows of customers_default_address_id are set to a same wrong address id.

something is wrong with the customers.php, customers_default_address_id should only update only 1 customer.

Thank you

20 Dec 2023, 7:46 PM
#11
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Post #11 by swguy

This is not a bug. You are deliberately screwing up your data. There's no way AFAIK for this to happen organically unless you're attacking your own database.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

20 Dec 2023, 11:36 PM
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #12 by mc12345678

jjone:

This is a zen cart 1.5.8a bug

This is how to test it: first change all customer default address id to a same number with following sql.

UPDATE customers set customers_default_address_id = 10


Now, login to your zen cart admin and goto Customers and click on any customer

after that, open phpMyAdmin and refresh the customers tables

all rows of customers_default_address_id are set to a same wrong address id.

something is wrong with the customers.php, customers_default_address_id should only update only 1 customer.

Thank you

To put it another way, there is no expectation that every customer would have the same address_book_id. The issue to try to understand is how did they all end up the same?

So see, if the data was all wrong, then yes the queries against it and other associated code would work unexpectedly. As such there does not actually appear to be a problem with the code in that area unless an operation while using it changes the value for all customers to a single value.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

21 Dec 2023, 11:16 AM
#13
daxtheman avatar

daxtheman

New Zenner

Join Date:
Jun 2023
Location:
UK
Posts:
21
Plugin Contributions:
0

Post #13 by daxtheman

Hi

I will re-create the scenario I experienced on a test server using the same data (which I have backup up from live site) and report back.

I noticed that when this happened there were quite a few logs complaining about htmlspecialcharacters and pointing to classes>customer.php...lines 791,811,830 and 847.

22 Dec 2023, 12:32 AM
#14
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Post #14 by gothstone

Dax - Maybe we should be trying to figure out what we have in common that ate both our databases about the same time. Did you recently switch to square? Did you install lat9's access blocker? Do you host on liquid web? What have you done recently that maybe I did too and am not thinking about?

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

2 Jan 2024, 9:55 AM
#15
daxtheman avatar

daxtheman

New Zenner

Join Date:
Jun 2023
Location:
UK
Posts:
21
Plugin Contributions:
0

Post #15 by daxtheman

Hi Gothstone

I recently switched to Square. That would appear to be the common denominator.

Also, before correcting my database I saved the customer and address book tables. Reviewing those there is one entry where the customer ID is missing from the address_book table sequence. That missing ID happened when the database went haywire. They hadn't purchased anything so the Square module wasn't triggered.

Still at a loss what happened.

12 Jan 2024, 10:04 PM
#16
zamzom avatar

zamzom

New Zenner

Join Date:
Jun 2009
Location:
Europe
Posts:
60
Plugin Contributions:
0

Post #16 by zamzom

DaxtheMan:

Me Again!

Okay, so I have noticed something that may be the cause. In the table 'Customers' the 'customers_default_address_id' column has the same for every customer!

I feel that the number there should match the address_book_ id in the address_book table but doesn't.

Can anyone confirm that the assumption above is correct?

If so, can anyone suggest a way to re-connect the two tables so they tally?

Thanks

Dax

Yes, it is a bug.
In classes/Customers.php around line 354:

protected function setDefaultAddressBookId(int $id)
    {
        global $db;
        $sql = "UPDATE " . TABLE_CUSTOMERS . " SET customers_default_address_id=" . (int)$id;
        $db->Execute($sql);
        $this->data['customers_default_address_id'] = (int)$id;
    }

THIS UPDATE STATEMENT CHANGES DEFAULT ADDRESS BOOK ID OF ALL CUSTOMERS, SINCE THERE IS NO WHERE STATEMENT!

13 Jan 2024, 10:28 AM
#17
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Post #17 by swguy

This is a bug in Zen Cart 1.5.8/1.5.8a which was fixed in Zen Cart 2.0.0.

Credit to @marco-pm for fixing this!

https://github.com/zencart/zencart/pull/5687

And credit to @zamzom for tracking this down - I had long since forgotten this issue.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

15 Apr 2026, 6:43 PM
#18
djdavedawson avatar

djdavedawson

Zen Follower

Join Date:
Jul 2005
Location:
Orlando, Fl
Posts:
343
Plugin Contributions:
0

Post #18 by djdavedawson

gothstone:

Dax - Maybe we should be trying to figure out what we have in common that ate both our databases about the same time. Did you recently switch to square? Did you install lat9's access blocker? Do you host on liquid web? What have you done recently that maybe I did too and am not thinking about?

Goth, curious, why do you ask about liquid web here?

15 Apr 2026, 10:32 PM
#19
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Post #19 by swguy

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.