Skip to content

Duplicate state PaymentAccepted since version 1.16.5 #14

@eballetbaz

Description

@eballetbaz

After upgrade from version 1.16.1 to latest version 1.23.0 each order shows duplicate state "Payment Accepted" and customer receive duplicate emails.

My prestashop version is 1.7.8.7

I found that root cause of issue has been added in version 1.16.5: "Bug fix: Fix payment in installments invoice for PrestaShop 1.7.x and higher."
This block code has been added and it generate an extra OrderHistory with an extra email

        if (version_compare(_PS_VERSION_, '1.7', '>')) {
            // Send email upon the update of the payment.
            $order_history = new OrderHistory();
            $order_history->id_order = (int) $order->id;
            $order_history->id_order_state = $order->getCurrentState();
            if (! $order_history->addWithemail(true)) {
                $this->logger->logInfo("Failed to send email when updating payments for cart #{$cart->id}.");
            }

            // Delete double entry from history.
            $result = Db::getInstance()->execute(
                'DELETE FROM `' . _DB_PREFIX_ . 'order_history` WHERE `id_order` = ' . (int) $order->id . ' AND `id_order_state` = '
                    . (int) $order->getCurrentState() . ' ORDER BY `date_add` DESC LIMIT 1');

            if (! $result) {
                $this->logger->logWarning("An error occurred when deleting history for order #{$order->id}.");
            }
        }

When I remove this code, situation is back to normal

Indeed in current code, the order is update twice :

  • at row 2193 by calling validateOrder which calls $new_history->addWithemail(true, $extra_vars);
  • at row 2221 by calling if (! $order_history->addWithemail(true)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions