View Full Version : Primary Address Changing After Session Timeout

09-25-2008, 01:07 AM
Hi Guys,

I'm having a problem with my address book. In particular, when I go into the address book and change one of the addresses to "Primary Address", the Primary Address changes to a different address after the session times out.

It's giving me a bit of a headache trying to figure this one out. I've checked the database and the Primary Address is set to the selected address after I go into address_book_process.php and set the desired Primary Address. However, upon timeout of the session (i.e. the customer is automatically logged out after being idle for too long, or returns to the account the next day for example), the database value is rewritten to a different default address.

I think something is being written incorrectly into the session, but haven't been able to find a solution. Has anyone come across this or have any ideas for a fix?


10-02-2008, 11:22 AM
Well, it took over a week to find the cause but I got it :D
The problem didn't stem from session timeouts, but from a coding issue in the admin section.

For anyone else who experiences this (it's a standard installation of oscmax, so this should affect everyone), there's a dodgy piece of code in admin/customers.php:

<?php // BOF: MOD - Edit Order - Ajout/edite commande et compte client
$customersrecords = mysql_query("SELECT * FROM customers") or die ("Wha Happen??? Error 1");
while($customerrows = tep_db_fetch_array($customersrecords)) {
$e = mysql_query("SELECT * FROM address_book WHERE customers_id ='$customerrows[customers_id]'") or die ("What Happen??? Error 2");
$real = tep_db_fetch_array($e);
$updatedefaultaddress = mysql_query("UPDATE customers SET customers_default_address_id = '$real[address_book_id]' WHERE customers_id='$customerrows[customers_id]'") or die ("What Happen??? Error 3");
// BOF: MOD - Edit Order - Ajout/edite commande et compte client ?>Whenever customers.php is accessed through admin, it will update every customer's primary address to the first entry for that customer in the 'address_book' table.

Hope this saves someone else some time!

10-07-2008, 08:04 AM
I probably should have said, just delete the code above from your customers.php file to remove this bug.

10-14-2008, 11:12 PM
Could anyone else confirm this please? Makes me wonder why this hasn't gone on the bugtracker or what on earth that code is supposed to do in there...

10-14-2008, 11:34 PM
It was never reported, so that is why it was never in the bugtracker. The bug has been documented now:

I just checked the order editor mod, and this is in fact deprecated code that should be removed.

This was fixed in the order editor mod as of v1.72, so osCMax does need this bugfix too:

Modified so that Customer, Shipping, and Billing address fields are all displayed and are editable. My versions are built off v1.61b and in that version only Billing and Shipping address fields were shown, except that the info for Billing Address was being taken from Customer Address fields which is WRONG WRONG WRONG.

When done this way, any time you updated an order, the customer address information would overwrite the billing address information. I changed that so it makes sense.

Also I added a line into the language definition file so that you can have "Customer Address" as a table heading as well as just "Address" as a line heading.

Which reminds me, I have not updated any of the included language definition files besides the english version for the changes I have made. Sorry. If you are using any of the other languages on your shop, you will have to update the appropriate language definition files.