Skip to content

Commit 554f668

Browse files
committed
exclude AC-10042: /V1/transactions REST API returns error when parent_txn_id = txn_id
1 parent 5e0e51e commit 554f668

File tree

4 files changed

+32
-47
lines changed

4 files changed

+32
-47
lines changed

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

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Sales\Model\ResourceModel\Order\Payment;
87

98
use Magento\Sales\Model\ResourceModel\EntityAbstract;
@@ -12,6 +11,7 @@
1211
/**
1312
* Sales transaction resource model
1413
*
14+
* @author Magento Core Team <core@magentocommerce.com>
1515
*/
1616
class Transaction extends EntityAbstract implements TransactionResourceInterface
1717
{
@@ -34,8 +34,7 @@ protected function _construct()
3434

3535
/**
3636
* Update transactions in database using provided transaction as parent for them
37-
*
38-
* Have to repeat the business logic to avoid accidental injection of wrong transactions
37+
* have to repeat the business logic to avoid accidental injection of wrong transactions
3938
*
4039
* @param \Magento\Sales\Model\Order\Payment\Transaction $transaction
4140
* @return void
@@ -127,7 +126,6 @@ public function getOrderWebsiteId($orderId)
127126

128127
/**
129128
* Lookup for parent_id in already saved transactions of this payment by the order_id
130-
*
131129
* Also serialize additional information, if any
132130
*
133131
* @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Model\Order\Payment\Transaction $transaction
@@ -148,14 +146,9 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
148146
__('We don\'t have enough information to save the parent transaction ID.')
149147
);
150148
}
151-
/*$parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
149+
$parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
152150
if ($parentId) {
153151
$transaction->setData('parent_id', $parentId);
154-
}*/
155-
} else {
156-
$oldParentTxnId = $this->getParentTxnId($orderId);
157-
if ($oldParentTxnId) {
158-
$transaction->setData('parent_txn_id', $oldParentTxnId);
159152
}
160153
}
161154

@@ -176,7 +169,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
176169
* @param int $orderId
177170
* @param int $paymentId
178171
* @param string $txnId
179-
* @param mixed $columns (array|string|object) $columns
172+
* @param mixed (array|string|object) $columns
180173
* @param bool $isRow
181174
* @param string $txnType
182175
* @return array|string
@@ -218,22 +211,4 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column
218211
$txnId
219212
);
220213
}
221-
/**
222-
* Retrieve transaction by the unique key of order_id
223-
*
224-
* @param int $orderId
225-
* @return string
226-
*/
227-
private function getParentTxnId(int $orderId): string
228-
{
229-
$connection = $this->getConnection();
230-
$select = $connection->select()->from(
231-
$this->getMainTable(),
232-
['parent_txn_id']
233-
)->where(
234-
'order_id = ?',
235-
$orderId
236-
);
237-
return $connection->fetchOne($select);
238-
}
239214
}

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

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

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

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

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

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

7472
$serviceInfo = [
7573
'rest' => [
@@ -167,15 +165,10 @@ public function testTransactionList()
167165
$this->assertArrayHasKey('items', $result);
168166

169167
$transactionData = $this->getPreparedTransactionData($transaction);
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-
}
168+
$childTransactionData = $this->getPreparedTransactionData($childTransaction);
169+
$transactionData['child_transactions'][] = $childTransactionData;
170+
$expectedData = [$transactionData, $childTransactionData];
171+
$this->assertEquals($expectedData, $result['items']);
179172
$this->assertArrayHasKey('search_criteria', $result);
180173
$this->assertEquals($searchData, $result['search_criteria']);
181174
}

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ public function __construct(
6767

6868
/**
6969
* @inheritdoc
70+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7071
*/
71-
public function build(Schema $schema)
72+
public function build(Schema $schema, $tablesWithJsonTypeField = [])
7273
{
7374
foreach ($this->sharding->getResources() as $resource) {
7475
foreach ($this->dbSchemaReader->readTables($resource) as $tableName) {
@@ -95,9 +96,16 @@ public function build(Schema $schema)
9596
'collation' => $tableOptions['collation']
9697
]
9798
);
99+
$isJsonType = false;
100+
if (count($tablesWithJsonTypeField) > 0 && isset($tablesWithJsonTypeField[$tableName])) {
101+
$isJsonType = true;
102+
}
98103

99104
// Process columns
100105
foreach ($columnsData as $columnData) {
106+
if ($isJsonType && $tablesWithJsonTypeField[$tableName] == $columnData['name']) {
107+
$columnData['type'] = 'json';
108+
}
101109
$columnData['table'] = $table;
102110
$column = $this->elementFactory->create($columnData['type'], $columnData);
103111
$columns[$column->getName()] = $column;

lib/internal/Magento/Framework/Setup/Declaration/Schema/SchemaConfig.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ public function __construct(
6262
*/
6363
public function getDbConfig()
6464
{
65+
$declarativeSchema = $this->getDeclarationConfig();
66+
$tablesWithJsonTypeField = [];
67+
foreach ($declarativeSchema->getTables() as $table) {
68+
foreach ($table->getColumns() as $column) {
69+
if ($column->getType() == 'json') {
70+
$tablesWithJsonTypeField[$table->getName()] = $column->getName();
71+
}
72+
}
73+
}
6574
$schema = $this->schemaFactory->create();
66-
$schema = $this->dbSchemaBuilder->build($schema);
75+
$schema = $this->dbSchemaBuilder->build($schema, $tablesWithJsonTypeField);
6776
return $schema;
6877
}
6978

0 commit comments

Comments
 (0)