Skip to content

Commit 44547cb

Browse files
committed
Merge remote-tracking branch 'origin/AC-10042' into spartans_pr_15042024
2 parents c38c279 + 4ecd1e8 commit 44547cb

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Transaction.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
/**
1212
* Sales transaction resource model
1313
*
14-
* @author Magento Core Team <core@magentocommerce.com>
1514
*/
1615
class 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
}

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/TransactionTest.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class TransactionTest extends WebapiAbstract
1919
/**
2020
* Service read name
2121
*/
22-
const SERVICE_READ_NAME = 'salesTransactionRepositoryV1';
22+
public const SERVICE_READ_NAME = 'salesTransactionRepositoryV1';
2323

2424
/**
2525
* Resource path for REST
2626
*/
27-
const RESOURCE_PATH = '/V1/transactions';
27+
public const RESOURCE_PATH = '/V1/transactions';
2828

2929
/**
3030
* Service version
3131
*/
32-
const SERVICE_VERSION = 'V1';
32+
public const SERVICE_VERSION = 'V1';
3333

3434
/**
3535
* @var \Magento\Framework\ObjectManagerInterface
@@ -66,8 +66,10 @@ public function testTransactionGet()
6666
$childTransaction = reset($childTransactions);
6767

6868
$expectedData = $this->getPreparedTransactionData($transaction);
69-
$childTransactionData = $this->getPreparedTransactionData($childTransaction);
70-
$expectedData['child_transactions'][] = $childTransactionData;
69+
if (gettype($childTransaction) != 'boolean') {
70+
$childTransactionData = $this->getPreparedTransactionData($childTransaction);
71+
$expectedData['child_transactions'][] = $childTransactionData;
72+
}
7173

7274
$serviceInfo = [
7375
'rest' => [
@@ -165,10 +167,15 @@ public function testTransactionList()
165167
$this->assertArrayHasKey('items', $result);
166168

167169
$transactionData = $this->getPreparedTransactionData($transaction);
168-
$childTransactionData = $this->getPreparedTransactionData($childTransaction);
169-
$transactionData['child_transactions'][] = $childTransactionData;
170-
$expectedData = [$transactionData, $childTransactionData];
171-
$this->assertEquals($expectedData, $result['items']);
170+
if (gettype($childTransaction) != 'boolean') {
171+
$childTransactionData = $this->getPreparedTransactionData($childTransaction);
172+
$transactionData['child_transactions'][] = $childTransactionData;
173+
$expectedData = [$transactionData, $childTransactionData];
174+
$this->assertEquals($expectedData, $result['items']);
175+
} else {
176+
$expectedData = $transactionData;
177+
$this->assertEquals($expectedData, $result['items'][0]);
178+
}
172179
$this->assertArrayHasKey('search_criteria', $result);
173180
$this->assertEquals($searchData, $result['search_criteria']);
174181
}

0 commit comments

Comments
 (0)