Problem/Motivation
The SQL select which selects the abandoned carts gets multiple rows with order_id and mail for orders with more than one line item. After that when the emails are sent to users we get an error for the second result row with the same order_id and mail when the module would like to insert the proper row to the commerce_abandoned_carts table (the user gets 2 emails):
Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '225' for key 'PRIMARY': INSERT INTO {commerce_abandoned_carts} (order_id, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 225 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1620283164 ) in Drupal\Core\Database\Connection->handleQueryException() (line 698 of /var/www/html/www/core/lib/Drupal/Core/Database/Connection.php).
Proposed resolution
The select needs to be modified to get only distinct rows and in this case only one email will be sent for an order.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | interdiff.txt | 403 bytes | dj1999 |
| #4 | 3212480-SQL-error-orders-with-multiple-line-items-4.patch | 1017 bytes | dj1999 |
| #2 | 3212480-SQL-error-orders-with-multiple-line-items-2.patch | 723 bytes | kosa ilma |
Comments
Comment #2
kosa ilma commentedPatch.
Comment #3
kosa ilma commentedComment #4
dj1999 commentedBecause I need to alter this query added a tag. Please review.
Comment #5
nikita_ttConfirm it works. Thanks!
Comment #6
nicxvan commentedI think this might just be a duplicate of https://www.drupal.org/project/commerce_abandoned_carts/issues/3366213
But that one has fewer changes. Do you think this can be closed as a duplicate?
Comment #7
megachrizThis has been fixed in #3366213: Orders with multiple order items generate multiple emails.