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.

Comments

Kosa Ilma created an issue. See original summary.

kosa ilma’s picture

kosa ilma’s picture

Status: Active » Needs review
dj1999’s picture

Because I need to alter this query added a tag. Please review.

nikita_tt’s picture

Confirm it works. Thanks!

nicxvan’s picture

I 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?

megachriz’s picture

Status: Needs review » Closed (duplicate)