1111/**
1212 * Sales transaction resource model
1313 *
14- * @author Magento Core Team <core@magentocommerce.com>
1514 */
1615class Transaction extends EntityAbstract implements TransactionResourceInterface
1716{
@@ -34,7 +33,8 @@ protected function _construct()
3433
3534 /**
3635 * Update transactions in database using provided transaction as parent for them
37- * have to repeat the business logic to avoid accidental injection of wrong transactions
36+ *
37+ * Have to repeat the business logic to avoid accidental injection of wrong transactions
3838 *
3939 * @param \Magento\Sales\Model\Order\Payment\Transaction $transaction
4040 * @return void
@@ -126,6 +126,7 @@ public function getOrderWebsiteId($orderId)
126126
127127 /**
128128 * Lookup for parent_id in already saved transactions of this payment by the order_id
129+ *
129130 * Also serialize additional information, if any
130131 *
131132 * @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Model\Order\Payment\Transaction $transaction
@@ -146,9 +147,14 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
146147 __ ('We don \'t have enough information to save the parent transaction ID. ' )
147148 );
148149 }
149- $ parentId = (int )$ this ->_lookupByTxnId ($ orderId , $ paymentId , $ parentTxnId , $ idFieldName );
150+ /* $parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
150151 if ($parentId) {
151152 $transaction->setData('parent_id', $parentId);
153+ }*/
154+ } else {
155+ $ oldParentTxnId = $ this ->getParentTxnId ($ orderId );
156+ if ($ oldParentTxnId ) {
157+ $ transaction ->setData ('parent_txn_id ' , $ oldParentTxnId );
152158 }
153159 }
154160
@@ -169,7 +175,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
169175 * @param int $orderId
170176 * @param int $paymentId
171177 * @param string $txnId
172- * @param mixed (array|string|object) $columns
178+ * @param mixed $columns (array|string|object) $columns
173179 * @param bool $isRow
174180 * @param string $txnType
175181 * @return array|string
@@ -211,4 +217,21 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column
211217 $ txnId
212218 );
213219 }
220+ /**
221+ * Retrieve transaction by the unique key of order_id
222+ *
223+ * @param int $orderId
224+ */
225+ protected function getParentTxnId ($ orderId )
226+ {
227+ $ connection = $ this ->getConnection ();
228+ $ select = $ connection ->select ()->from (
229+ $ this ->getMainTable (),
230+ ['parent_txn_id ' ]
231+ )->where (
232+ 'order_id = ? ' ,
233+ $ orderId
234+ );
235+ return $ connection ->fetchOne ($ select );
236+ }
214237}
0 commit comments