From 541413c31e95397f1affd530d96fcf87c7173751 Mon Sep 17 00:00:00 2001 From: Diego Torres Date: Fri, 26 Jan 2024 10:43:20 -0300 Subject: [PATCH] SG-322 add successful payment data in Payment Information section, in admin order view --- Model/Simplified.php | 2 +- Plugin/Block/Adminhtml/SalesOrderViewInfo.php | 67 +++++++++++++++++++ README.md | 5 +- composer.json | 2 +- etc/adminhtml/di.xml | 6 ++ etc/module.xml | 4 +- view/adminhtml/layout/sales_order_view.xml | 9 +++ .../templates/order/view/custom.phtml | 30 +++++++++ 8 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 Plugin/Block/Adminhtml/SalesOrderViewInfo.php create mode 100644 etc/adminhtml/di.xml create mode 100644 view/adminhtml/layout/sales_order_view.xml create mode 100644 view/adminhtml/templates/order/view/custom.phtml diff --git a/Model/Simplified.php b/Model/Simplified.php index 352b4ff..2889345 100755 --- a/Model/Simplified.php +++ b/Model/Simplified.php @@ -22,7 +22,7 @@ class Simplified extends \Magento\Payment\Model\Method\AbstractMethod { - const KHIPU_MAGENTO_VERSION = "2.4.8"; + const KHIPU_MAGENTO_VERSION = "2.4.9"; protected $_code = 'simplified'; protected $_isInitializeNeeded = true; protected $urlBuilder; diff --git a/Plugin/Block/Adminhtml/SalesOrderViewInfo.php b/Plugin/Block/Adminhtml/SalesOrderViewInfo.php new file mode 100644 index 0000000..667f8bc --- /dev/null +++ b/Plugin/Block/Adminhtml/SalesOrderViewInfo.php @@ -0,0 +1,67 @@ +orderRepository = $orderRepository; + } + + /** + * @param \Magento\Sales\Block\Adminhtml\Order\View\Info $subject + * @param string $result + * @return string + */ + public function afterToHtml( + \Magento\Sales\Block\Adminhtml\Order\View\Info $subject, + $result + ) + { + $orderId = $subject->getOrder()->getId(); + $paymentInformation = $this->getOrderStatusHistoryComment($orderId); + + $customBlock = $subject->getLayout()->getBlock('custom_block'); + if ($customBlock !== false && $subject->getNameInLayout() == 'order_info') { + $customBlock->setData('payment_information', $paymentInformation); + $result = $result; + } + return $result; + } + + /** + * Retrieve order status history comment + * + * @param int $orderId + * @return string + */ + protected function getOrderStatusHistoryComment($orderId) + { + try { + $order = $this->orderRepository->get($orderId); + $orderStatusHistory = $order->getStatusHistories(); + + // Reverse the array to get the last status history comment + $reversedOrderStatusHistory = array_reverse($orderStatusHistory); + $lastStatusHistory = array_pop($reversedOrderStatusHistory); + + return $lastStatusHistory ? $lastStatusHistory->getComment() : ''; + } catch (\Exception $e) { + // Handle exception if needed + return ''; + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 415050f..3511fc5 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Magento 2 Khipu Plugin -khipu payment gateway Magento 2.4.8 plugin. +khipu payment gateway Magento 2.4.9 plugin. This version is compatible with Magento 2.3 to 2.6 @@ -8,7 +8,7 @@ You can sign up for khipu account at ## Install via Composer -You can install Magento 2.4.8 khipu plugin via [Composer](http://getcomposer.org/). Run the following command in your terminal: +You can install Magento 2.4.9 khipu plugin via [Composer](http://getcomposer.org/). Run the following command in your terminal: 1. Go to your Magento 2 root folder. @@ -17,6 +17,7 @@ You can install Magento 2.4.8 khipu plugin via [Composer](http://getcomposer.org ```bash composer require khipu/magento2-khipu ``` + Wait while dependencies are updated. 3. Enter following commands to enable plugin: diff --git a/composer.json b/composer.json index a151d1e..cc722c4 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "khipu/magento2-khipu", "type": "magento2-module", "description": "khipu integration for Magento 2", - "version": "2.4.8", + "version": "2.4.9", "homepage": "https://khipu.com", "license": [ "OSL-3.0" diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml new file mode 100644 index 0000000..261230f --- /dev/null +++ b/etc/adminhtml/di.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/etc/module.xml b/etc/module.xml index e04210b..ae9b575 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - - + + diff --git a/view/adminhtml/layout/sales_order_view.xml b/view/adminhtml/layout/sales_order_view.xml new file mode 100644 index 0000000..7d6ac4e --- /dev/null +++ b/view/adminhtml/layout/sales_order_view.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/templates/order/view/custom.phtml b/view/adminhtml/templates/order/view/custom.phtml new file mode 100644 index 0000000..cf057c7 --- /dev/null +++ b/view/adminhtml/templates/order/view/custom.phtml @@ -0,0 +1,30 @@ +
+
+ getData('payment_information')): ?> + /i', $paymentInformation); + $firstLine = reset($lines); + + if (strpos($firstLine, 'Pago Khipu Aceptado') !== false): + ?> + + + + + + + +
+ + +
+
\ No newline at end of file