diff --git a/Block/Adminhtml/Order/View/SubstituteWarning.php b/Block/Adminhtml/Order/View/SubstituteWarning.php new file mode 100644 index 00000000..36aec292 --- /dev/null +++ b/Block/Adminhtml/Order/View/SubstituteWarning.php @@ -0,0 +1,217 @@ +. + * + * PHP version 5 + * + * @category Payone + * @package Payone_Magento2_Plugin + * @author FATCHIP GmbH + * @copyright 2003 - 2024 Payone GmbH + * @license 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; + } +} \ No newline at end of file diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 51bc8fd1..282abbff 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -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" diff --git a/view/adminhtml/layout/sales_order_view.xml b/view/adminhtml/layout/sales_order_view.xml index 9bcce148..939df294 100644 --- a/view/adminhtml/layout/sales_order_view.xml +++ b/view/adminhtml/layout/sales_order_view.xml @@ -26,6 +26,9 @@ --> + + + diff --git a/view/adminhtml/templates/order_substitute_warning.phtml b/view/adminhtml/templates/order_substitute_warning.phtml new file mode 100644 index 00000000..df877181 --- /dev/null +++ b/view/adminhtml/templates/order_substitute_warning.phtml @@ -0,0 +1,37 @@ +. + * + * PHP version 5 + * + * @category Payone + * @package Payone_Magento2_Plugin + * @author FATCHIP GmbH + * @copyright 2003 - 2024 Payone GmbH + * @license GNU Lesser General Public License + * @link http://www.payone.de + */ + +/** @var Payone\Core\Block\Adminhtml\Order\View\SubstituteWarning $block */ +?> +
+ hasSubstituteOrder()): ?> +
+ + getSubstituteOrderIncrementNr(); ?> + isSubstituteOrder() === true): ?> + + getOrder()->getPayoneCancelSubstituteIncrementId(); ?> + +
\ No newline at end of file