11
11
/**
12
12
* Sales transaction resource model
13
13
*
14
- * @author Magento Core Team <core@magentocommerce.com>
15
14
*/
16
15
class Transaction extends EntityAbstract implements TransactionResourceInterface
17
16
{
@@ -34,7 +33,8 @@ protected function _construct()
34
33
35
34
/**
36
35
* 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
38
38
*
39
39
* @param \Magento\Sales\Model\Order\Payment\Transaction $transaction
40
40
* @return void
@@ -126,6 +126,7 @@ public function getOrderWebsiteId($orderId)
126
126
127
127
/**
128
128
* Lookup for parent_id in already saved transactions of this payment by the order_id
129
+ *
129
130
* Also serialize additional information, if any
130
131
*
131
132
* @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Model\Order\Payment\Transaction $transaction
@@ -146,9 +147,14 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
146
147
__ ('We don \'t have enough information to save the parent transaction ID. ' )
147
148
);
148
149
}
149
- $ parentId = (int )$ this ->_lookupByTxnId ($ orderId , $ paymentId , $ parentTxnId , $ idFieldName );
150
+ /* $parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
150
151
if ($parentId) {
151
152
$transaction->setData('parent_id', $parentId);
153
+ }*/
154
+ } else {
155
+ $ oldParentTxnId = $ this ->getParentTxnId ($ orderId );
156
+ if ($ oldParentTxnId ) {
157
+ $ transaction ->setData ('parent_txn_id ' , $ oldParentTxnId );
152
158
}
153
159
}
154
160
@@ -169,7 +175,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
169
175
* @param int $orderId
170
176
* @param int $paymentId
171
177
* @param string $txnId
172
- * @param mixed (array|string|object) $columns
178
+ * @param mixed $columns (array|string|object) $columns
173
179
* @param bool $isRow
174
180
* @param string $txnType
175
181
* @return array|string
@@ -211,4 +217,21 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column
211
217
$ txnId
212
218
);
213
219
}
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
+ }
214
237
}
0 commit comments