Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 9 additions & 7 deletions Observer/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\Request\Http as Request;
use Magento\Framework\App\Response\Http as Response;
use Magento\Framework\App\Response\RedirectInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Message\ManagerInterface;
Expand All @@ -29,6 +30,8 @@ abstract class Validate implements ObserverInterface

protected Response $response;

protected RedirectInterface $redirect;

protected Validator $validator;

protected Json $json;
Expand All @@ -45,7 +48,6 @@ abstract class Validate implements ObserverInterface

/**
* @param ManagerInterface $messageManager
* @param Response $response
* @param Validator $validator
* @param Json $json
* @param Config $config
Expand All @@ -54,15 +56,15 @@ abstract class Validate implements ObserverInterface
*/
public function __construct(
ManagerInterface $messageManager,
Response $response,
RedirectInterface $redirect,
Validator $validator,
Json $json,
Config $config,
?PersistorInterface $persistor = null,
array $data = []
) {
$this->messageManager = $messageManager;
$this->response = $response;
$this->redirect = $redirect;
$this->validator = $validator;
$this->json = $json;
$this->config = $config;
Expand All @@ -78,8 +80,9 @@ public function __construct(
*/
public function execute(Observer $observer): void
{
$this->action = $observer->getEvent()->getData('controller_action');
$this->request = $observer->getEvent()->getData('request');
$this->action = $observer->getEvent()->getData('controller_action');
$this->request = $observer->getEvent()->getData('request');
$this->response = $this->action->getResponse();

if ($this->canValidate()) {
try {
Expand Down Expand Up @@ -114,9 +117,8 @@ public function getCfResponse(): ?string
protected function error(Phrase $message): void
{
$this->messageManager->addErrorMessage($message);
$this->response->setRedirect($this->request?->getServer('HTTP_REFERER', '/') ?? '/');
$this->redirect->redirect($this->response, $this->redirect->getRefererUrl());

$this->response->sendResponse();
Comment thread
csharp-isi marked this conversation as resolved.
exit();
}

Expand Down
7 changes: 3 additions & 4 deletions Observer/Validate/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Magento\Customer\Controller\Ajax\Login as AjaxLoginPost;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Response\Http as Response;
use Magento\Framework\App\Response\RedirectInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Phrase;
use Magento\Framework\Serialize\Serializer\Json;
Expand All @@ -27,7 +27,6 @@ class Frontend extends Validate

/**
* @param ManagerInterface $messageManager
* @param Response $response
* @param Validator $validator
* @param Json $json
* @param Config $config
Expand All @@ -37,8 +36,8 @@ class Frontend extends Validate
*/
public function __construct(
ManagerInterface $messageManager,
Response $response,
Validator $validator,
RedirectInterface $redirect,
Json $json,
Config $config,
CustomerSession $customerSession,
Expand All @@ -47,7 +46,7 @@ public function __construct(
) {
$this->customerSession = $customerSession;

parent::__construct($messageManager, $response, $validator, $json, $config, $persistor, $data);
parent::__construct($messageManager, $redirect, $validator, $json, $config, $persistor, $data);
}


Expand Down