SQL error if we have orders with multiple line items

Created on 6 May 2021, over 3 years ago
Updated 29 April 2024, 7 months ago

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.

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡΄Romania Kosa Ilma

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024