This doesn't seem to be related to any additional modules as I've been testing it a lot.
When someone logs in it all goes to the same controller, but if the $_POST variable context is set to checkout, alternative code is run to tweak/adjust the quote/basket in progress. This normally occurs from one page step 1 for a logged out user.
When turning on the right debugging, this results in:
Customer Login Failed Reg: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`somedbname`.`sales_flat_quote_shipping_rate`, CONSTRAINT `FK_B1F177EFB73D3EDF5322BA64AC48D150` FOREIGN KEY (`address_id`) REFERENCES `sales_flat_quote_address` (`address_id`) ON DELETE CASC)
Digging thru the code, it runs setQuoteGuest when the context is set, from line 437 of public_html/app/code/core/Mage/Persistent/Model/Observer.php
This deletes the quote addresses and then updates them. Of course the update fails and the code trips thru the rest of the code till it tries to insert into sales_flat_quote_shipping_rate which is where the integrity constraint comes in.
Queries:
2014-03-31T16:10:06+00:00 DEBUG (7): DELETE FROM `sales_flat_quote_address` WHERE (address_id='1')
2014-03-31T16:10:06+00:00 DEBUG (7): DELETE FROM `sales_flat_quote_address` WHERE (address_id='2')
2014-03-31T16:10:07+00:00 DEBUG (7): UPDATE `sales_flat_quote_address` SET `quote_id` = ?, `updated_at` = '2014-03-31 16:10:07', `customer_id` = ?, `address_type` = ?, `country_id` = ?, `collect_shipping_rates` = ?, `subtotal` = ?, `base_subtotal` = ?, `grand_total` = ?, `base_grand_total` = ? WHERE (address_id='1')
and in full
## 2014-03-31 16:10:06
## 41801 ## QUERY
SQL: SELECT `main_table`.* FROM `sales_flat_quote_address` AS `main_table` WHERE (quote_id = '1')
AFF: 2
TIME: 0.0007
## 2014-03-31 16:10:06
## 41801 ## TRANSACTION BEGIN
TIME: 0.0001
## 2014-03-31 16:10:06
## 41801 ## QUERY
SQL: DELETE FROM `sales_flat_quote_address` WHERE (address_id='1')
AFF: 1
TIME: 0.0331
## 2014-03-31 16:10:06
## 41801 ## TRANSACTION COMMIT
TIME: 0.0563
## 2014-03-31 16:10:06
## 41801 ## TRANSACTION BEGIN
TIME: 0.0001
## 2014-03-31 16:10:06
## 41801 ## QUERY
SQL: DELETE FROM `sales_flat_quote_address` WHERE (address_id='2')
AFF: 1
TIME: 0.0008
## 2014-03-31 16:10:06
## 41801 ## TRANSACTION COMMIT
TIME: 0.1874
## 2014-03-31 16:10:07
## 41801 ## TRANSACTION BEGIN
TIME: 0.0001
## 2014-03-31 16:10:07
## 41801 ## QUERY
SQL: UPDATE `sales_flat_quote_address` SET `quote_id` = ?, `updated_at` = '2014-03-31 16:10:07', `customer_id` = ?, `address_type` = ?, `country_id` = ?, `collect_shipping_rates` = ?, `subtotal` = ?, `base_subtotal` = ?, `grand_total` = ?, `base_grand_total` = ? WHERE (address_id='1')
BIND: array (
0 => 1,
1 => NULL,
2 => 'billing',
3 => 'GB',
4 => 1,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
)
AFF: 0
So, have I stumbled on a Magento bug?
Line 447 of said observer
$quote->getPaymentsCollection()->walk('delete');
$quote->getAddressesCollection()->walk('delete');
$this->_setQuotePersistent = false;
$quote
->setIsActive(true)
->setCustomerId(null)
->setCustomerEmail(null)
->setCustomerFirstname(null)
->setCustomerLastname(null)
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
->setIsPersistent(false)
->removeAllAddresses();
//Create guest addresses
$quote->getShippingAddress();
$quote->getBillingAddress();
$quote->collectTotals()->save();
Seems to delete the addresses and then try to update the addresses it just deleted. \o/
I've traced as much as I can and now I'm stuck. I'm about to setup a proper blank install of Magento to compare. But thought I'd seek the knowledge of the hive. As I have no idea if it's me of Magento at fault!
Update: It's works fine on a plain Vanilla Magento.
Update 2: Looks like it's something in WebShop Apps. Checking which part now…
Update 3: It's not WebShop Apps. It's something derpy