-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9064 from magento-gl/spartans_pr_04072024
[Spartans] Bugfixes Delivery
- Loading branch information
Showing
9 changed files
with
154 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
/** | ||
* Sales transaction resource model | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
class Transaction extends EntityAbstract implements TransactionResourceInterface | ||
{ | ||
|
@@ -34,7 +33,8 @@ protected function _construct() | |
|
||
/** | ||
* Update transactions in database using provided transaction as parent for them | ||
* have to repeat the business logic to avoid accidental injection of wrong transactions | ||
* | ||
* Have to repeat the business logic to avoid accidental injection of wrong transactions | ||
* | ||
* @param \Magento\Sales\Model\Order\Payment\Transaction $transaction | ||
* @return void | ||
|
@@ -126,11 +126,14 @@ public function getOrderWebsiteId($orderId) | |
|
||
/** | ||
* Lookup for parent_id in already saved transactions of this payment by the order_id | ||
* | ||
* Also serialize additional information, if any | ||
* | ||
* @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Model\Order\Payment\Transaction $transaction | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
* @return $this | ||
* | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
*/ | ||
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction) | ||
{ | ||
|
@@ -139,16 +142,23 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti | |
$orderId = $transaction->getData('order_id'); | ||
$paymentId = $transaction->getData('payment_id'); | ||
$idFieldName = $this->getIdFieldName(); | ||
|
||
$txnType = $transaction->getData('txn_type'); | ||
if ($parentTxnId) { | ||
if (!$txnId || !$orderId || !$paymentId) { | ||
throw new \Magento\Framework\Exception\LocalizedException( | ||
__('We don\'t have enough information to save the parent transaction ID.') | ||
); | ||
} | ||
$parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName); | ||
if ($parentId) { | ||
if ($parentId && $txnType == 'authorization') { | ||
$transaction->setData('parent_id', $parentId); | ||
$transaction->setData('txn_type', \Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE); | ||
} | ||
} else { | ||
$result = $this->getParentId($orderId); | ||
if ($result) { | ||
$transaction->setData('parent_id', $result[0]['transaction_id']); | ||
$transaction->setData('parent_txn_id', $result[0]['parent_txn_id']); | ||
} | ||
} | ||
|
||
|
@@ -169,7 +179,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti | |
* @param int $orderId | ||
* @param int $paymentId | ||
* @param string $txnId | ||
* @param mixed (array|string|object) $columns | ||
* @param mixed $columns (array|string|object) $columns | ||
* @param bool $isRow | ||
* @param string $txnType | ||
* @return array|string | ||
|
@@ -211,4 +221,23 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column | |
$txnId | ||
); | ||
} | ||
|
||
/** | ||
* Retrieve transaction by the unique key of order_id | ||
* | ||
* @param int $orderId | ||
* @return array | ||
*/ | ||
protected function getParentId(int $orderId): array | ||
{ | ||
$connection = $this->getConnection(); | ||
$select = $connection->select()->from( | ||
$this->getMainTable(), | ||
['transaction_id','parent_txn_id'] | ||
)->where( | ||
'order_id = ?', | ||
$orderId | ||
)->order('transaction_id', 'ASC')->limit(1); | ||
return $connection->fetchAll($select); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.