Page 1 of 1

Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Thu Sep 27, 2018 7:14 am
by ipthena
OC 3.0.2.0
When a new customer chooses to register during the checkout process, they enter in their payment address and click continue. By default the "My delivery and billing addresses are the same." is checked, BUT it still asks for shipping address. At that point it seems the customer account is created/saved to the database, and the payment address they entered is saved to customer_ID = 1! (not to their new customer_ID). The checkout asks for the shipping address and still allows them to proceed with checkout, but the order comes in without a payment address. BUt i can see that customer's address in the very first customer's account (customer_ID = 1). It also throws an error in my PayPal Payflow Pro iFrame gateway (not even sure why it still accepts the payment without a payment address but that's a different issue):
2018-09-26 18:06:10 - PHP Notice: Undefined index: code in catalog/controller/extension/payment/pp_payflow_iframe.php on line 46
2018-09-26 18:06:10 - PHP Notice: Undefined index: iso_code_2 in catalog/controller/extension/payment/pp_payflow_iframe.php on line 48

I have turned off my themes but it still does the same. I have installed i on 2 difference servers and again, same issue. Am I the only one???

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Thu Sep 27, 2018 10:12 pm
by ipthena
There seems to be a problem with obtaining the last customer ID added to the database in file catalog\model\account\customer.php line 16:
$customer_id = $this->db->getLastId();

I also get an error when I try my Affiliate Registration:
PHP Fatal error: Uncaught Exception: Error: Duplicate entry '1' for key 'PRIMARY'<br />Error No: 1062<br />INSERT INTO customer_affiliate SET `customer_id` = '1'

So that function getLastId() is pulling the first ID instead of the last. I'm not the most skilled PHP developer, so help is appreciated thanks!

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Fri Sep 28, 2018 7:14 am
by straightlight
The last ID method does pull the last inserted ID rather than the first as it is supposed to. However, what you might be looking for would be the next un-existing one next to the latest added ID on the database. Let's try this.

In catalog/model/account/customer.php file,

find:

Code: Select all

$customer_id = $this->db->getLastId();
replace with:

Code: Select all

$customer_id = $this->db->getLastId('customer_id', DB_PREFIX . 'customer');
Then, in system/library/db/mysqli.php file (if using mySQLi extension), replace:

Code: Select all

public function getLastId() {
		return $this->connection->insert_id;
	}
with:

Code: Select all

public function getLastId($column = '', $table = '') {
		if (!empty($column) && !empty($table)) {
			$sql = "SELECT MAX(`" . $column . "`) AS `max_id` FROM `" . $table . "`";
			
			$row = $this->connection->query($sql);
			
			return (($row['max_id'] + 1) > 0 ? (int)$row['max_id'] + 1 : 1);		
		} else {
			return $this->connection->insert_id;
		}
	}
Then, try again with the checkout customer registration. This modification also works for the customer registration without checkout on the store-front end.

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Fri Sep 28, 2018 9:10 pm
by ipthena
Thanks straightlight! Is this a known bug in OC 3.0.2.0? I would think more people would have noticed it. I hesitate changing that piece of code if it's not the real cause of the issue. I've been doing a lot of googling. Does it matter that i'm hosted on GoDaddy and maybe something isn't turned on to all that code to run properly?

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Sat Sep 29, 2018 4:21 am
by straightlight
If you hesitate to follow the suggested code change, then you'll never know if it does actually resolved the issue. However, it is not an OC bug.

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Sat Sep 29, 2018 5:14 am
by ipthena
Well I'm just concerned that this issue may be caused by some other factor (not the OC code itself) - maybe where i'm hosted, maybe a plugin. Anyway, i did test your suggestions but it's still doing the same thing. I really had hoped that your code would have patched it up for me so i could finalize this project! :) I cleared my OC cache as well as my browser cache and still got the same result: new customer registration payment address was saved to customer_ID 1

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Sat Sep 29, 2018 5:33 am
by straightlight
If the new customer ID was saved as value 1, then it means that the last ID from your database could not be tracked in from your server. Not an OC issue as all OC does at this point is to gather the last inserted ID and with my modifications, it adds a + 1 to it. If the + 1 result cannot be returned, it's an issue from your server.

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Sat Sep 29, 2018 5:48 am
by ipthena
i appreciate your help! I'm on GoDaddy. I have OC 1.5.6.1 hosted on there as well (same hosting account) - and that did not have an issue. I compared both mysqli.php files and they both get the last inserted ID the same - same function. So now I'm even more perplexed.

Re: Checkout Register New Customer Payment Address Saving to Different Customer Account

Posted: Tue Oct 02, 2018 3:17 am
by ipthena
SOLVED IT! After a TON of testing, I discovered that the GetResponse Module was causing the issue. I have not yet investigated as to why it was causing it, but i have confirmed from uninstalling the module the cart worked properly, then re-installed it and it again failed. I will be contacting GetResponse to report the issue. I very much appreciate your help! Hope this thread helps someone else that may be having the same issue.