From 7d8047a88106889e445e13a941325457852faf46 Mon Sep 17 00:00:00 2001 From: Daniil Tkachev Date: Wed, 9 Oct 2024 11:54:40 +0200 Subject: [PATCH] UNZER-475 Fix backend admin paymentId handling --- src/Controller/Admin/AdminOrderController.php | 2 +- src/Service/Transaction.php | 39 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Controller/Admin/AdminOrderController.php b/src/Controller/Admin/AdminOrderController.php index 165806b9..4d0bf986 100644 --- a/src/Controller/Admin/AdminOrderController.php +++ b/src/Controller/Admin/AdminOrderController.php @@ -88,7 +88,7 @@ public function render() $transactionService = $this->getServiceFromContainer(TransactionService::class); $orderId = $this->getEditObjectId(); - $paymentId = $transactionService->getPaymentIdByOrderId($orderId, true); //somthesing like s-chg-XXXX + $paymentId = $transactionService->getAdminPaymentIdByOrderId($orderId); //somthesing like s-chg-XXXX $this->sTypeId = $paymentId; /** may@throws \TypeError if $paymentId due to wrong payment cancellation */ $this->_aViewData['sTypeId'] = $this->sTypeId; if ($this->sTypeId) { diff --git a/src/Service/Transaction.php b/src/Service/Transaction.php index dd84824c..4c198f47 100644 --- a/src/Service/Transaction.php +++ b/src/Service/Transaction.php @@ -457,9 +457,7 @@ public function getPaymentIdByOrderId(string $orderid, bool $withoutCancel = fal $queryBuilder = $queryBuilderFactory->create(); $query = $queryBuilder - ->select( - 'typeid' - ) + ->select('typeid') ->from('oscunzertransaction') ->distinct() ->where($queryBuilder->expr()->eq('oxorderid', ':oxorderid')) @@ -480,6 +478,41 @@ public function getPaymentIdByOrderId(string $orderid, bool $withoutCancel = fal return $result; } + /** + * @param string $orderid + * @param bool $withoutCancel + * @return string + * @throws Exception + * @throws \Doctrine\DBAL\Exception + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ + public function getAdminPaymentIdByOrderId(string $orderid, bool $withoutCancel = false): string + { + $result = ''; + + $queryBuilderFactory = $this->getServiceFromContainer(QueryBuilderFactoryInterface::class); + $queryBuilder = $queryBuilderFactory->create(); + + $query = $queryBuilder + ->select('typeid') + ->from('oscunzertransaction') + ->distinct() + ->where($queryBuilder->expr()->eq('oxorderid', ':oxorderid')) + ->setMaxResults(1); + + $parameters = [ + ':oxorderid' => $orderid, + ]; + + $queryResult = $query->setParameters($parameters)->execute(); + if ($queryResult instanceof ResultStatement && $queryResult->columnCount()) { + $result = $queryResult->fetchOne(); + $result = is_string($result) ? $result : ''; + } + + return $result; + } + /** * @param string $orderid * @return string