Skip to content
Draft
Changes from all commits
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
39 changes: 37 additions & 2 deletions Service/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\View\DesignInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\ResourceModel\Order\Payment;
Expand All @@ -22,6 +23,7 @@

class Result
{
private const HYVA_CHECKOUT_PAYMENT_PAGE = 'checkout/index/index/step/payment';
/** @var ResultFactory */
private $resultFactory;

Expand Down Expand Up @@ -54,6 +56,12 @@ class Result
/** @var Payment */
private $paymentResource;

/** @var DesignInterface */
private $design;

/** @var ManagerInterface */
private $messageManager;

/**
* @param ResultFactory $resultFactory
* @param SessionManagerInterface $checkoutSession
Expand All @@ -64,6 +72,8 @@ class Result
* @param Emulation $emulation
* @param LoggerInterface $logger
* @param Payment $paymentResource
* @param DesignInterface $design
* @param ManagerInterface $messageManager
*/
public function __construct(
ResultFactory $resultFactory,
Expand All @@ -74,7 +84,9 @@ public function __construct(
OrderInterface $order,
Emulation $emulation,
LoggerInterface $logger,
Payment $paymentResource
Payment $paymentResource,
DesignInterface $design,
ManagerInterface $messageManager
) {
$this->resultFactory = $resultFactory;
$this->checkoutSession = $checkoutSession;
Expand All @@ -85,6 +97,8 @@ public function __construct(
$this->emulation = $emulation;
$this->logger = $logger;
$this->paymentResource = $paymentResource;
$this->design = $design;
$this->messageManager = $messageManager;
}

/**
Expand Down Expand Up @@ -190,6 +204,12 @@ private function processResultPage(ProcessOrderResultInterface $result, bool $re
if ($result->getRedirectPath() === IN::FAILURE) {
$params['_fragment'] = 'payment';
$messageGroup = SessionMessageInterface::MESSAGE_GROUP;
if ($this->isHyvaThemeUsed()) {
$result->setRedirectPath(self::HYVA_CHECKOUT_PAYMENT_PAGE);
}
}
if ($result->getCustomerMessage() && $this->isHyvaThemeUsed()) {
$this->messageManager->addErrorMessage($result->getCustomerMessage());
}

$result->setSessionMessage($messageGroup ?? null);
Expand All @@ -198,4 +218,19 @@ private function processResultPage(ProcessOrderResultInterface $result, bool $re

return $redirect;
}

/**
* @return bool
*/
private function isHyvaThemeUsed(): bool
{
$theme = $this->design->getDesignTheme();
while ($theme) {
if (strpos($theme->getCode(), 'Hyva/') === 0) {
return true;
}
$theme = $theme->getParentTheme();
}
return false;
}
}