Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-1190: Add functions that provide details for the invoices. #105

Merged
merged 6 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Plugin/AddTemplateVariable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Mondu\Mondu\Plugin;

use Mondu\Mondu\Helpers\Log as MonduLogger;
use Mondu\Mondu\Helpers\Logger\Logger as MonduFileLogger;

class AddTemplateVariable
{
/**
* @var MonduLogger
*/
private MonduLogger $monduLogger;

/**
* @var MonduFileLogger
*/
private MonduFileLogger $monduFileLogger;

/**
* @param MonduLogger $monduLogger
* @param MonduFileLogger $monduFileLogger
*/
public function __construct(
MonduLogger $monduLogger,
MonduFileLogger $monduFileLogger
) {
$this->monduLogger = $monduLogger;
$this->monduFileLogger = $monduFileLogger;
}

/**
* @param \Magento\Email\Model\Template $subject
* @param array $vars
*
* @return array[]
*/
public function beforeSetVars(
\Magento\Email\Model\Template $subject,
array $vars
) {
if (!$vars['order'] || !$vars['order']->getMonduReferenceId()) {
return [$vars];
}

try {
$monduReferenceId = $vars['order']->getMonduReferenceId();
$monduLog = $this->monduLogger->getLogCollection($monduReferenceId);

if (!$monduLog) {
return [$vars];
}

$vars['monduDetails'] = $this->prepareHtml($monduLog);
} catch (\Exception $e) {
$this->monduFileLogger->critical($e->getMessage());
}

return [$vars];
}

/**
* @param $monduLog
*
* @return string
*/
protected function prepareHtml($monduLog)
{
$html = '';

if ($monduLog['payment_method']) {
$html .= '<strong>Payment Method:</strong> ' . ucwords(strtolower($monduLog['payment_method'])) . '<br />';
tikohov20 marked this conversation as resolved.
Show resolved Hide resolved
}

if ($monduLog['invoice_iban']) {
$html .= '<strong>IBAN:</strong> ' . $monduLog['invoice_iban'] . '<br />';
}

if ($monduLog['authorized_net_term']) {
$html .= '<strong>Net Terms:</strong> ' . $monduLog['authorized_net_term'] . '<br />';
}

return $html;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mondu_gmbh/magento2-payment",
"description": "Mondu payment method for magento 2",
"type": "magento2-module",
"version": "2.3.3",
"version": "2.3.4",
"license": [
"MIT"
],
Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
<type name="Magento\Payment\Helper\Data">
<plugin sortOrder="10" name="monduPaymentData" type="Mondu\Mondu\Helpers\DataPlugin"/>
</type>
<type name="Magento\Email\Model\Template">
<plugin sortOrder="10" name="addTemplateVariable" type="Mondu\Mondu\Plugin\AddTemplateVariable"/>
</type>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mondu_Mondu" setup_version="2.3.3">
<module name="Mondu_Mondu" setup_version="2.3.4">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down