-
Notifications
You must be signed in to change notification settings - Fork 1
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 #7 from khipu/SG-322
SG-322 add successful payment data in Payment Information section, in admin order view
Showing
8 changed files
with
119 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Khipu\Payment\Plugin\Block\Adminhtml; | ||
|
||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
|
||
class SalesOrderViewInfo | ||
{ | ||
/** | ||
* @var OrderRepositoryInterface | ||
*/ | ||
protected $orderRepository; | ||
|
||
|
||
/** | ||
* @param OrderRepositoryInterface $orderRepository | ||
*/ | ||
public function __construct( | ||
OrderRepositoryInterface $orderRepository | ||
) { | ||
$this->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 ''; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Sales\Block\Adminhtml\Order\View\Info"> | ||
<plugin name="custom_block_add" type="Khipu\Payment\Plugin\Block\Adminhtml\SalesOrderViewInfo" sortOrder="10" /> | ||
</type> | ||
</config> |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="order_additional_info"> | ||
<block class="Magento\Backend\Block\Template" name="custom_block" template="Khipu_Payment::order/view/custom.phtml" after="-" /> | ||
</referenceBlock> | ||
</body> | ||
</page> |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<section class="admin__page-section"> | ||
<div class="admin__page-section-content"> | ||
<?php if ($paymentInformation = $block->getData('payment_information')): ?> | ||
<?php | ||
$lines = preg_split('/<br\s*\/?>/i', $paymentInformation); | ||
$firstLine = reset($lines); | ||
|
||
if (strpos($firstLine, 'Pago Khipu Aceptado') !== false): | ||
?> | ||
<table class="admin__table-secondary order-information-table" style="width: 50%;"> | ||
<?php | ||
foreach ($lines as $line): | ||
$parts = explode(': ', trim($line)); | ||
$label = isset($parts[0]) ? $parts[0] : ''; | ||
$value = isset($parts[1]) ? $parts[1] : ''; | ||
|
||
if (empty($label) && empty($value)) { | ||
continue; | ||
} | ||
?> | ||
<tr> | ||
<th style="width: 30%;"><?php echo $label; ?></th> | ||
<td><?php echo $value; ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</table> | ||
<?php endif; ?> | ||
<?php endif; ?> | ||
</div> | ||
</section> |