diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Transaction.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Transaction.php index 916d359105b94..09641e89f3c0c 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Transaction.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Transaction.php @@ -153,7 +153,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti $transaction->setData('parent_id', $parentId); } } else { - $result = $this->getParentId($orderId); + $result = $this->getParentId($orderId, (string)$transaction->getTransactionId()); if ($result) { $transaction->setData('parent_id', $result[0]['transaction_id']); $transaction->setData('parent_txn_id', $result[0]['parent_txn_id']); @@ -224,9 +224,10 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column * Retrieve transaction by the unique key of order_id * * @param int $orderId + * @param string $currentTransactionId * @return array */ - protected function getParentId(int $orderId): array + protected function getParentId(int $orderId, string $currentTransactionId): array { $connection = $this->getConnection(); $select = $connection->select()->from( @@ -235,6 +236,9 @@ protected function getParentId(int $orderId): array )->where( 'order_id = ?', $orderId + )->where( + 'transaction_id <> ?', + $currentTransactionId )->order('transaction_id', 'ASC')->limit(1); return $connection->fetchAll($select); }