Skip to content

Commit cfe65bd

Browse files
Merge MAGETWO-94340 into 2.1.16-bugfixes-311018
2 parents 4a043b3 + d13dc14 commit cfe65bd

File tree

1 file changed

+29
-3
lines changed
  • app/code/Magento/Sales/Controller/AbstractController

1 file changed

+29
-3
lines changed

app/code/Magento/Sales/Controller/AbstractController/Reorder.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
namespace Magento\Sales\Controller\AbstractController;
88

99
use Magento\Framework\App\Action;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Data\Form\FormKey\Validator;
1012
use Magento\Framework\Registry;
13+
use Magento\Framework\Exception\NotFoundException;
14+
use Magento\Framework\Controller\ResultFactory;
1115

1216
abstract class Reorder extends Action\Action
1317
{
@@ -21,18 +25,26 @@ abstract class Reorder extends Action\Action
2125
*/
2226
protected $_coreRegistry;
2327

28+
/**
29+
* @var Validator
30+
*/
31+
private $formKeyValidator;
32+
2433
/**
2534
* @param Action\Context $context
2635
* @param OrderLoaderInterface $orderLoader
2736
* @param Registry $registry
37+
* @param Validator|null $formKeyValidator
2838
*/
2939
public function __construct(
3040
Action\Context $context,
3141
OrderLoaderInterface $orderLoader,
32-
Registry $registry
42+
Registry $registry,
43+
Validator $formKeyValidator = null
3344
) {
3445
$this->orderLoader = $orderLoader;
3546
$this->_coreRegistry = $registry;
47+
$this->formKeyValidator = $formKeyValidator ?: ObjectManager::getInstance()->create(Validator::class);
3648
parent::__construct($context);
3749
}
3850

@@ -43,6 +55,20 @@ public function __construct(
4355
*/
4456
public function execute()
4557
{
58+
if ($this->getRequest()->isPost()) {
59+
if (!$this->formKeyValidator->validate($this->getRequest())) {
60+
$this->messageManager->addErrorMessage(__('Invalid Form Key. Please refresh the page.'));
61+
62+
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
63+
$redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
64+
$redirect->setPath('*/*/history');
65+
66+
return $redirect;
67+
}
68+
} else {
69+
throw new NotFoundException(__('Page not found.'));
70+
}
71+
4672
$result = $this->orderLoader->load($this->_request);
4773
if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
4874
return $result;
@@ -52,13 +78,13 @@ public function execute()
5278
$resultRedirect = $this->resultRedirectFactory->create();
5379

5480
/* @var $cart \Magento\Checkout\Model\Cart */
55-
$cart = $this->_objectManager->get('Magento\Checkout\Model\Cart');
81+
$cart = $this->_objectManager->get(\Magento\Checkout\Model\Cart::class);
5682
$items = $order->getItemsCollection();
5783
foreach ($items as $item) {
5884
try {
5985
$cart->addOrderItem($item);
6086
} catch (\Magento\Framework\Exception\LocalizedException $e) {
61-
if ($this->_objectManager->get('Magento\Checkout\Model\Session')->getUseNotice(true)) {
87+
if ($this->_objectManager->get(\Magento\Checkout\Model\Session::class)->getUseNotice(true)) {
6288
$this->messageManager->addNotice($e->getMessage());
6389
} else {
6490
$this->messageManager->addError($e->getMessage());

0 commit comments

Comments
 (0)