From ef6fcd128876ae5e6291d3baadb4fa584aed57d7 Mon Sep 17 00:00:00 2001 From: Kamil Balwierz Date: Mon, 16 Feb 2026 08:24:04 +0100 Subject: [PATCH 1/3] Remove OrderRepository override Load orders directly via OrderRepository utilising cache. As some clients claim to rely on nonperisted updated visible in OrderRepository object cache --- Controller/Tpay/Create.php | 1 + Controller/Tpay/Redirect.php | 4 ++- Cron/CancelOverdue.php | 2 +- Helper/OrderResolver.php | 43 +++++++++++++++++++++++++++++++++ Model/Sales/OrderRepository.php | 30 ----------------------- Model/TpayPayment.php | 22 ++++++++--------- Service/TpayService.php | 18 +++++++++----- etc/di.xml | 1 - 8 files changed, 71 insertions(+), 50 deletions(-) create mode 100644 Helper/OrderResolver.php delete mode 100644 Model/Sales/OrderRepository.php diff --git a/Controller/Tpay/Create.php b/Controller/Tpay/Create.php index d03817c0..04884664 100644 --- a/Controller/Tpay/Create.php +++ b/Controller/Tpay/Create.php @@ -73,6 +73,7 @@ public function execute(): ResultInterface if ($orderId) { $payment = $this->tpayService->getPayment($orderId); $paymentData = $payment->getData(); + $additionalPaymentInformation = $paymentData['additional_information']; if (!$additionalPaymentInformation[TpayInterface::TERMS_ACCEPT]) { diff --git a/Controller/Tpay/Redirect.php b/Controller/Tpay/Redirect.php index d1d4923d..404df325 100644 --- a/Controller/Tpay/Redirect.php +++ b/Controller/Tpay/Redirect.php @@ -52,7 +52,9 @@ public function execute(): ResultInterface return $this->redirectFactory->redirectCheckoutCart(); } - $additionalPaymentInfo = $this->tpayService->getPayment($orderId)->getData()['additional_information']; + $order = $this->checkoutSession->getLastRealOrder(); + + $additionalPaymentInfo = $order->getPayment()->getData()['additional_information']; if ($this->additionalPaymentInfoValidator->validateCardData($additionalPaymentInfo)) { return $this->redirectFactory->redirectCardPayment(); diff --git a/Cron/CancelOverdue.php b/Cron/CancelOverdue.php index be155391..cbb6787d 100644 --- a/Cron/CancelOverdue.php +++ b/Cron/CancelOverdue.php @@ -6,11 +6,11 @@ use DateTime; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Sales\Model\Order; +use Magento\Sales\Model\OrderRepository; use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface; use Tpay\Magento2\Api\TpayInterface; -use Tpay\Magento2\Model\Sales\OrderRepository; class CancelOverdue { diff --git a/Helper/OrderResolver.php b/Helper/OrderResolver.php new file mode 100644 index 00000000..381e8ac1 --- /dev/null +++ b/Helper/OrderResolver.php @@ -0,0 +1,43 @@ +orderRepository = $orderRepository; + $this->orderResource = $orderResource; + } + + public function getOrderByIncrementId(string $incrementId): OrderInterface + { + $orderId = $this->getOrderIdByIncrementId($incrementId); + + return $this->orderRepository->get($orderId); + } + + public function getOrderIdByIncrementId(string $incrementId): int + { + if (!isset($this->cache[$incrementId])) { + $connection = $this->orderResource->getConnection(); + $select = $connection->select()->from($this->orderResource->getMainTable(), ['entity_id'])->where('increment_id = ?', $incrementId); + $orderId = $connection->fetchOne($select); + $this->cache[$incrementId] = (int) $orderId; + } + + return $this->cache[$incrementId]; + } +} diff --git a/Model/Sales/OrderRepository.php b/Model/Sales/OrderRepository.php deleted file mode 100644 index 4f016325..00000000 --- a/Model/Sales/OrderRepository.php +++ /dev/null @@ -1,30 +0,0 @@ -metadata->getNewInstance()->loadByIncrementId($incrementId); - - if (!$entity->getEntityId()) { - throw new NoSuchEntityException(__('Requested entity doesn\'t exist')); - } - - return $entity; - } -} diff --git a/Model/TpayPayment.php b/Model/TpayPayment.php index 2212d182..033538ed 100755 --- a/Model/TpayPayment.php +++ b/Model/TpayPayment.php @@ -24,11 +24,12 @@ use Magento\Payment\Model\Method\Adapter; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Api\Data\PaymentInterface; +use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order\Payment\Transaction; use Magento\Store\Model\StoreManager; use Psr\Log\LoggerInterface; -use Tpay\Magento2\Api\Sales\OrderRepositoryInterface; use Tpay\Magento2\Api\TpayInterface; +use Tpay\Magento2\Helper\OrderResolver; use Tpay\Magento2\Model\ApiFacade\Refund\RefundApiFacade; use Tpay\Magento2\Provider\ConfigurationProvider; use Tpay\OriginApi\Validators\FieldsValidator; @@ -58,9 +59,6 @@ class TpayPayment extends Adapter implements TpayInterface /** @var CustomerSession */ protected $customerSession; - /** @var OrderRepositoryInterface */ - protected $orderRepository; - /** @var Escaper */ protected $escaper; @@ -82,6 +80,9 @@ class TpayPayment extends Adapter implements TpayInterface /** @var CacheInterface */ protected $cache; + /** @var OrderResolver */ + private $orderResolver; + private $supportedVendors = [ 'visa', 'jcb', @@ -104,7 +105,7 @@ public function __construct( UrlInterface $urlBuilder, Session $checkoutSession, CustomerSession $customerSession, - OrderRepositoryInterface $orderRepository, + OrderResolver $orderResolver, Escaper $escaper, StoreManager $storeManager, ConfigurationProvider $configurationProvider, @@ -129,7 +130,7 @@ public function __construct( $this->escaper = $escaper; $this->checkoutSession = $checkoutSession; $this->customerSession = $customerSession; - $this->orderRepository = $orderRepository; + $this->orderResolver = $orderResolver; $this->storeManager = $storeManager; $this->configurationProvider = $configurationProvider; $this->infoInstance = $infoInstance; @@ -305,8 +306,7 @@ public function getCheckoutTotal() $amount = (float) $this->getCheckout()->getQuote()->getBaseGrandTotal(); if (!$amount && $this->getCheckout()->getLastRealOrderId()) { - $orderId = $this->getCheckout()->getLastRealOrderId(); - $order = $this->orderRepository->getByIncrementId($orderId); + $order = $this->getCheckout()->getLastRealOrder(); $amount = $order->getBaseGrandTotal(); } @@ -378,12 +378,12 @@ protected function getCheckout(): Session return $this->checkoutSession; } - protected function getOrder(?string $orderId = null): \Magento\Sales\Api\Data\OrderInterface + protected function getOrder(?string $orderId = null): OrderInterface { if (null === $orderId) { - $orderId = $this->getCheckout()->getLastRealOrderId(); + return $this->getCheckout()->getLastRealOrder(); } - return $this->orderRepository->getByIncrementId($orderId); + return $this->orderResolver->getOrderByIncrementId($orderId); } } diff --git a/Service/TpayService.php b/Service/TpayService.php index 734a71b7..055b377f 100644 --- a/Service/TpayService.php +++ b/Service/TpayService.php @@ -7,10 +7,11 @@ use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Api\OrderPaymentRepositoryInterface; +use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Payment\Transaction; use Magento\Sales\Model\Service\InvoiceService; -use Tpay\Magento2\Api\Sales\OrderRepositoryInterface; +use Tpay\Magento2\Helper\OrderResolver; class TpayService { @@ -23,19 +24,24 @@ class TpayService /** @var InvoiceService */ protected $invoiceService; + /** @var OrderResolver */ + private $orderResolver; + public function __construct( OrderRepositoryInterface $orderRepository, OrderPaymentRepositoryInterface $orderPaymentRepository, - InvoiceService $invoiceService + InvoiceService $invoiceService, + OrderResolver $orderResolver ) { $this->orderRepository = $orderRepository; $this->orderPaymentRepository = $orderPaymentRepository; $this->invoiceService = $invoiceService; + $this->orderResolver = $orderResolver; } public function setOrderStatePendingPayment(string $orderId, bool $sendEmail): OrderInterface { - $order = $this->orderRepository->getByIncrementId($orderId); + $order = $this->orderResolver->getOrderByIncrementId($orderId); $order ->setTotalDue($order->getBaseGrandTotal()) ->setTotalPaid(0.00) @@ -53,7 +59,7 @@ public function setOrderStatePendingPayment(string $orderId, bool $sendEmail): O public function addCommentToHistory($orderId, $comment) { /** @var Order $order */ - $order = $this->orderRepository->getByIncrementId($orderId); + $order = $this->orderResolver->getOrderByIncrementId($orderId); $order->addStatusToHistory($order->getState(), $comment); $this->orderRepository->save($order); } @@ -61,14 +67,14 @@ public function addCommentToHistory($orderId, $comment) public function getPayment(string $orderId): OrderPaymentInterface { /** @var Order $order */ - $order = $this->orderRepository->getByIncrementId($orderId); + $order = $this->orderResolver->getOrderByIncrementId($orderId); return $order->getPayment(); } public function getOrderById(string $orderId): OrderInterface { - return $this->orderRepository->getByIncrementId($orderId); + return $this->orderResolver->getOrderByIncrementId($orderId); } public function saveOrderPayment(OrderPaymentInterface $payment): OrderPaymentInterface diff --git a/etc/di.xml b/etc/di.xml index 4b8e35e7..de442315 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -13,7 +13,6 @@ - From 12fa1becc66fc07400bf00f5dffad76e197afbce Mon Sep 17 00:00:00 2001 From: Kamil Balwierz Date: Tue, 24 Feb 2026 14:08:36 +0100 Subject: [PATCH 2/3] Version 2.6.0 Changelog --- .version | 2 +- CHANGELOG.MD | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.version b/.version index aedc15bb..e70b4523 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.5.3 +2.6.0 diff --git a/CHANGELOG.MD b/CHANGELOG.MD index a6d3a84c..ec572039 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.6.0 + +### Changed + +- Removed OrderRepository override that provided loadByIncrementId method, loading order details using OrderRepository::get + ## 2.5.3 ### Added From a1df04a3af448733696dbc86ab68c707da0c3b4f Mon Sep 17 00:00:00 2001 From: Kamil Balwierz Date: Tue, 24 Feb 2026 14:12:42 +0100 Subject: [PATCH 3/3] codestyle --- Api/TpayConfigInterface.php | 4 +++- Api/TpayInterface.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Api/TpayConfigInterface.php b/Api/TpayConfigInterface.php index 0db7c24c..5aa9944f 100644 --- a/Api/TpayConfigInterface.php +++ b/Api/TpayConfigInterface.php @@ -4,7 +4,9 @@ namespace Tpay\Magento2\Api; -/** @api */ +/** + * @api + */ interface TpayConfigInterface { public function isTpayActive(): bool; diff --git a/Api/TpayInterface.php b/Api/TpayInterface.php index b4e8c7aa..c9ba55bd 100644 --- a/Api/TpayInterface.php +++ b/Api/TpayInterface.php @@ -4,7 +4,9 @@ namespace Tpay\Magento2\Api; -/** @api */ +/** + * @api + */ interface TpayInterface { public const CODE = 'Tpay_Magento2';