From 5231b7ff549d6ef67ca711d413253f50f802bf61 Mon Sep 17 00:00:00 2001 From: Vincent Boulanger Date: Thu, 30 May 2024 13:44:12 +0200 Subject: [PATCH] MAGE-536: Fix TxStatus association with relevant OrderId --- .../Protocol/TransactionStatus/Collection.php | 3 +++ .../TransactionStatusController.php | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/code/community/Payone/Core/Model/Domain/Resource/Protocol/TransactionStatus/Collection.php b/app/code/community/Payone/Core/Model/Domain/Resource/Protocol/TransactionStatus/Collection.php index ef8ecad3..5d793659 100644 --- a/app/code/community/Payone/Core/Model/Domain/Resource/Protocol/TransactionStatus/Collection.php +++ b/app/code/community/Payone/Core/Model/Domain/Resource/Protocol/TransactionStatus/Collection.php @@ -49,6 +49,9 @@ public function _construct() public function getByOrder(Mage_Sales_Model_Order $order) { $this->addFieldToFilter('order_id', $order->getId()); + if ($order->getData('increment_id') != 0) { + $this->addFilter('reference', $order->getData('increment_id'), 'or'); + } } /** diff --git a/app/code/community/Payone/Core/controllers/TransactionStatusController.php b/app/code/community/Payone/Core/controllers/TransactionStatusController.php index 9474592a..01b7d070 100644 --- a/app/code/community/Payone/Core/controllers/TransactionStatusController.php +++ b/app/code/community/Payone/Core/controllers/TransactionStatusController.php @@ -79,6 +79,27 @@ public function indexAction() // Handle Request: $response = $service->handleByPost(); + /** + * MAGE-536 : Fix missing OrderId and StoreId in TxStatus when reference exists + */ + if ($response->getStatus() == 'TSOK') { + /** @var $transactionStatusCollection Payone_Core_Model_Domain_Resource_Protocol_TransactionStatus_Collection */ + $transactionStatusCollection = Mage::getModel('payone_core/domain_protocol_transactionStatus') + ->getCollection(); + $transactionStatusCollection->getItemsByColumnValue('reference', $reference); + + /** @var Payone_Core_Model_Domain_Protocol_TransactionStatus $transactionStatus */ + foreach ($transactionStatusCollection as $transactionStatus) { + if (empty($transactionStatus->getOrderId())) { + $transactionStatus->setOrderId($order->getId()); + } + if (empty($transactionStatus->getStoreId())) { + $transactionStatus->setStoreId($order->getStoreId()); + } + $transactionStatus->save(); + } + } + // NEW forwarding handling $this->_forwardStatus($order);