Skip to content

Commit

Permalink
Merge pull request #564 from FatchipRobert/MAG2-325-Display-for-subst…
Browse files Browse the repository at this point in the history
…itute-orders-in-backend

MAG2-325 - Added an info in the backend concerning substitute orders
  • Loading branch information
janteuber authored Oct 4, 2024
2 parents 8ab9a9a + eb2a18c commit d14dee7
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 0 deletions.
217 changes: 217 additions & 0 deletions Block/Adminhtml/Order/View/SubstituteWarning.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<?php

/**
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
*
* PHP version 5
*
* @category Payone
* @package Payone_Magento2_Plugin
* @author FATCHIP GmbH <[email protected]>
* @copyright 2003 - 2024 Payone GmbH
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
* @link http://www.payone.de
*/

namespace Payone\Core\Block\Adminhtml\Order\View;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Sales\Model\Order;
use Magento\Framework\UrlInterface;
use Payone\Core\Helper\Database;

class SubstituteWarning extends Template
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;

/**
* @var Database
*/
protected $databaseHelper;

/**
* Order factory
*
* @var \Magento\Sales\Model\OrderFactory
*/
protected $orderFactory;

/**
* Url builder object
*
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var Order
*/
protected $oSubstituteOrder = null;

/**
* @param Context $context
* @param \Magento\Framework\Registry $registry
* @param Database $databaseHelper
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param UrlInterface $urlBuilder
* @param array $data
*/
public function __construct(
Context $context,
\Magento\Framework\Registry $registry,
Database $databaseHelper,
\Magento\Sales\Model\OrderFactory $orderFactory,
UrlInterface $urlBuilder,
array $data = []
) {
$this->_coreRegistry = $registry;
$this->databaseHelper = $databaseHelper;
$this->orderFactory = $orderFactory;
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $data);
}

/**
* Retrieve order model object
*
* @return \Magento\Sales\Model\Order
*/
public function getOrder()
{
return $this->_coreRegistry->registry('sales_order');
}

/**
* Checks if the current order is a substitute order
*
* @return bool
*/
public function isSubstituteOrder()
{
$oOrder = $this->getOrder();
if (!empty($oOrder->getPayoneCancelSubstituteIncrementId())) {
return true;
}
return false;
}

/**
* Check if the current order has a substitute order
*
* @return bool
*/
public function hasSubstituteOrder()
{
if ($this->getOrder()->getStatus() == Order::STATE_CANCELED && !empty($this->getSubstituteOrder())) {
return true;
}
return false;
}

/**
* @return Order|false
*/
protected function getSubstituteOrder()
{
if ($this->oSubstituteOrder === null) {
$this->oSubstituteOrder = false;

$sIncrementId = $this->databaseHelper->getSubstituteOrderIncrementId($this->getOrder()->getIncrementId());
if (!empty($sIncrementId)) {
$oOrder = $this->orderFactory->create()->loadByIncrementId($sIncrementId);
if ($oOrder && $oOrder->getId()) {
$this->oSubstituteOrder = $oOrder;
}
}
}
return $this->oSubstituteOrder;
}

protected function getOrigOrder()
{
$oOrder = $this->orderFactory->create()->loadByIncrementId($this->getOrder()->getPayoneCancelSubstituteIncrementId());
if ($oOrder && $oOrder->getId()) {
return $oOrder;
}
return false;
}

/**
* @return string
*/
protected function _toHtml()
{
if ($this->hasSubstituteOrder() || $this->isSubstituteOrder()) {
return parent::_toHtml();
}
return '';
}

/**
* Returns backend order url
*
* @param string $sOrderId
* @return string
*/
protected function getViewBackendOrderUrl($sOrderId)
{
return $this->urlBuilder->getUrl('sales/order/view', [
'order_id' => $sOrderId
]);
}

/**
* Returns URL to original order
*
* @return string
*/
public function getOrigOrderBackendUrl()
{
$oOrigOrder = $this->getOrigOrder();
if ($oOrigOrder) {
return $this->getViewBackendOrderUrl($oOrigOrder->getId());
}
return false;
}

/**
* @return string|false
*/
public function getSubstituteOrderBackendUrl()
{
$oSubstituteOrder = $this->getSubstituteOrder();
if (!empty($oSubstituteOrder)) {
return $this->getViewBackendOrderUrl($oSubstituteOrder->getId());
}
return false;
}

/**
* @return string|false
*/
public function getSubstituteOrderIncrementNr()
{
$oSubstituteOrder = $this->getSubstituteOrder();
if (!empty($oSubstituteOrder)) {
return $oSubstituteOrder->getIncrementId();
}
return false;
}
}
4 changes: 4 additions & 0 deletions i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,10 @@
"I want to transfer the installments myself and not pay by direct debit","Ich möchte die Ratenzahlung selbst vornehmen und nicht per Lastschrift begleichen"
"I want to settle the installments by direct debit","Ich möchte die Ratenzahlung per Lastschrift begleichen"

"This order has been canceled by a safety mechanism.","Diese Bestellung wurde von einen Sicherheitsmechanismus storniert."
"It has still been payed after cancellation. So a new substitute order has been created here: ","Sie wurde aber dennoch nach der Stornierung bezahlt. Daher wurde eine neue Ersatz-Bestellung angelegt hier: "
"This is a substitute order for: ","Dies ist eine Ersatz-Bestellung für: "

"PAYONE Credit Card", "PAYONE Kreditkarte"
"Safe installment is not available for your current basket. Please choose another payment method.","Gesicherter Ratenkauf wird für Ihren aktuellen Warenkorb nicht unterstützt. Bitte wählen Sie eine andere Zahlart."
"Payment with differing billing- and shipping-address is not supported for this payment type","Die Zahlung bei abweichender Rechnungs- und Lieferadressen wird für diese Zahlart nicht unterstützt"
Expand Down
3 changes: 3 additions & 0 deletions view/adminhtml/layout/sales_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Payone\Core\Block\Adminhtml\Order\View\SubstituteWarning" name="payone_sales_substitute_warning" before="sales_order_edit" template="order_substitute_warning.phtml" />
</referenceContainer>
<referenceBlock name="sales_order_tabs">
<block class="Payone\Core\Block\Adminhtml\Order\View\Tab\ApiLog" name="payone_sales_order_apilog.grid.container"/>
<action method="addTab">
Expand Down
37 changes: 37 additions & 0 deletions view/adminhtml/templates/order_substitute_warning.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
*
* PHP version 5
*
* @category Payone
* @package Payone_Magento2_Plugin
* @author FATCHIP GmbH <[email protected]>
* @copyright 2003 - 2024 Payone GmbH
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
* @link http://www.payone.de
*/

/** @var Payone\Core\Block\Adminhtml\Order\View\SubstituteWarning $block */
?>
<div style="background-color:#fffbbb; padding: 1rem;margin-bottom: 1rem;color: #676056;">
<?php if ($block->hasSubstituteOrder()): ?>
<?php echo __('This order has been canceled by a safety mechanism.'); ?><br>
<?php echo __('It has still been payed after cancellation. So a new substitute order has been created here: '); ?>
<a href="<?php echo $block->getSubstituteOrderBackendUrl(); ?>"><?php echo $block->getSubstituteOrderIncrementNr(); ?></a>
<?php elseif ($block->isSubstituteOrder() === true): ?>
<?php echo __('This is a substitute order for: '); ?>
<a href="<?php echo $block->getOrigOrderBackendUrl(); ?>"><?php echo $block->getOrder()->getPayoneCancelSubstituteIncrementId(); ?></a>
<?php endif; ?>
</div>

0 comments on commit d14dee7

Please sign in to comment.