Skip to content

Commit 5f9a631

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-45027' into BUGS
2 parents 733f260 + 7d610f0 commit 5f9a631

File tree

11 files changed

+286
-30
lines changed

11 files changed

+286
-30
lines changed

app/code/Magento/Wishlist/Controller/Index/Add.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Framework\App\Action;
10+
use Magento\Framework\Data\Form\FormKey\Validator;
1011
use Magento\Framework\Exception\NotFoundException;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Controller\ResultFactory;
@@ -31,22 +32,30 @@ class Add extends \Magento\Wishlist\Controller\AbstractIndex
3132
*/
3233
protected $productRepository;
3334

35+
/**
36+
* @var Validator
37+
*/
38+
protected $formKeyValidator;
39+
3440
/**
3541
* @param Action\Context $context
3642
* @param \Magento\Customer\Model\Session $customerSession
3743
* @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
3844
* @param ProductRepositoryInterface $productRepository
45+
* @param Validator $formKeyValidator
3946
*/
4047
public function __construct(
4148
Action\Context $context,
4249
\Magento\Customer\Model\Session $customerSession,
4350
\Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider,
44-
ProductRepositoryInterface $productRepository
51+
ProductRepositoryInterface $productRepository,
52+
Validator $formKeyValidator
4553
) {
4654
$this->_customerSession = $customerSession;
4755
$this->wishlistProvider = $wishlistProvider;
48-
parent::__construct($context);
4956
$this->productRepository = $productRepository;
57+
$this->formKeyValidator = $formKeyValidator;
58+
parent::__construct($context);
5059
}
5160

5261
/**
@@ -60,6 +69,12 @@ public function __construct(
6069
*/
6170
public function execute()
6271
{
72+
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
73+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
74+
if (!$this->formKeyValidator->validate($this->getRequest())) {
75+
return $resultRedirect->setPath('*/');
76+
}
77+
6378
$wishlist = $this->wishlistProvider->getWishlist();
6479
if (!$wishlist) {
6580
throw new NotFoundException(__('Page not found.'));
@@ -75,8 +90,6 @@ public function execute()
7590
}
7691

7792
$productId = isset($requestParams['product']) ? (int)$requestParams['product'] : null;
78-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
79-
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
8093
if (!$productId) {
8194
$resultRedirect->setPath('*/');
8295
return $resultRedirect;

app/code/Magento/Wishlist/Controller/Index/Cart.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,23 @@ class Cart extends \Magento\Wishlist\Controller\AbstractIndex
5959
*/
6060
protected $helper;
6161

62+
/**
63+
* @var \Magento\Framework\Data\Form\FormKey\Validator
64+
*/
65+
protected $formKeyValidator;
66+
6267
/**
6368
* @param Action\Context $context
6469
* @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
6570
* @param \Magento\Wishlist\Model\LocaleQuantityProcessor $quantityProcessor
6671
* @param \Magento\Wishlist\Model\ItemFactory $itemFactory
6772
* @param \Magento\Checkout\Model\Cart $cart
68-
* @param \Magento\Wishlist\Model\Item\OptionFactory $
73+
* @param \Magento\Wishlist\Model\Item\OptionFactory $optionFactory
6974
* @param \Magento\Catalog\Helper\Product $productHelper
7075
* @param \Magento\Framework\Escaper $escaper
7176
* @param \Magento\Wishlist\Helper\Data $helper
7277
* @param \Magento\Checkout\Helper\Cart $cartHelper
78+
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
7379
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7480
*/
7581
public function __construct(
@@ -82,7 +88,8 @@ public function __construct(
8288
\Magento\Catalog\Helper\Product $productHelper,
8389
\Magento\Framework\Escaper $escaper,
8490
\Magento\Wishlist\Helper\Data $helper,
85-
\Magento\Checkout\Helper\Cart $cartHelper
91+
\Magento\Checkout\Helper\Cart $cartHelper,
92+
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
8693
) {
8794
$this->wishlistProvider = $wishlistProvider;
8895
$this->quantityProcessor = $quantityProcessor;
@@ -93,6 +100,7 @@ public function __construct(
93100
$this->escaper = $escaper;
94101
$this->helper = $helper;
95102
$this->cartHelper = $cartHelper;
103+
$this->formKeyValidator = $formKeyValidator;
96104
parent::__construct($context);
97105
}
98106

@@ -108,9 +116,13 @@ public function __construct(
108116
*/
109117
public function execute()
110118
{
111-
$itemId = (int)$this->getRequest()->getParam('item');
112119
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
113120
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
121+
if (!$this->formKeyValidator->validate($this->getRequest())) {
122+
return $resultRedirect->setPath('*/*/');
123+
}
124+
125+
$itemId = (int)$this->getRequest()->getParam('item');
114126
/* @var $item \Magento\Wishlist\Model\Item */
115127
$item = $this->itemFactory->create()->load($itemId);
116128
if (!$item->getId()) {

app/code/Magento/Wishlist/Controller/Index/Fromcart.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Checkout\Model\Cart as CheckoutCart;
1010
use Magento\Customer\Model\Session;
1111
use Magento\Framework\App\Action;
12+
use Magento\Framework\Data\Form\FormKey\Validator;
1213
use Magento\Framework\Escaper;
1314
use Magento\Framework\Exception\NotFoundException;
1415
use Magento\Framework\Exception\LocalizedException;
@@ -46,27 +47,35 @@ class Fromcart extends \Magento\Wishlist\Controller\AbstractIndex
4647
*/
4748
protected $escaper;
4849

50+
/**
51+
* @var Validator
52+
*/
53+
protected $formKeyValidator;
54+
4955
/**
5056
* @param Action\Context $context
5157
* @param WishlistProviderInterface $wishlistProvider
5258
* @param WishlistHelper $wishlistHelper
5359
* @param CheckoutCart $cart
5460
* @param CartHelper $cartHelper
5561
* @param Escaper $escaper
62+
* @param Validator $formKeyValidator
5663
*/
5764
public function __construct(
5865
Action\Context $context,
5966
WishlistProviderInterface $wishlistProvider,
6067
WishlistHelper $wishlistHelper,
6168
CheckoutCart $cart,
6269
CartHelper $cartHelper,
63-
Escaper $escaper
70+
Escaper $escaper,
71+
Validator $formKeyValidator
6472
) {
6573
$this->wishlistProvider = $wishlistProvider;
6674
$this->wishlistHelper = $wishlistHelper;
6775
$this->cart = $cart;
6876
$this->cartHelper = $cartHelper;
6977
$this->escaper = $escaper;
78+
$this->formKeyValidator = $formKeyValidator;
7079
parent::__construct($context);
7180
}
7281

@@ -79,6 +88,12 @@ public function __construct(
7988
*/
8089
public function execute()
8190
{
91+
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
92+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
93+
if (!$this->formKeyValidator->validate($this->getRequest())) {
94+
return $resultRedirect->setPath('*/*/');
95+
}
96+
8297
$wishlist = $this->wishlistProvider->getWishlist();
8398
if (!$wishlist) {
8499
throw new NotFoundException(__('Page not found.'));
@@ -112,9 +127,6 @@ public function execute()
112127
} catch (\Exception $e) {
113128
$this->messageManager->addExceptionMessage($e, __('We can\'t move the item to the wish list.'));
114129
}
115-
116-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
117-
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
118130
return $resultRedirect->setUrl($this->cartHelper->getCartUrl());
119131
}
120132
}

app/code/Magento/Wishlist/Controller/Index/Remove.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,35 @@
66
namespace Magento\Wishlist\Controller\Index;
77

88
use Magento\Framework\App\Action;
9+
use Magento\Framework\Data\Form\FormKey\Validator;
910
use Magento\Framework\Exception\NotFoundException;
1011
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Wishlist\Controller\WishlistProviderInterface;
1113

1214
class Remove extends \Magento\Wishlist\Controller\AbstractIndex
1315
{
1416
/**
15-
* @var \Magento\Wishlist\Controller\WishlistProviderInterface
17+
* @var WishlistProviderInterface
1618
*/
1719
protected $wishlistProvider;
1820

21+
/**
22+
* @var Validator
23+
*/
24+
protected $formKeyValidator;
25+
1926
/**
2027
* @param Action\Context $context
21-
* @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
28+
* @param WishlistProviderInterface $wishlistProvider
29+
* @param Validator $formKeyValidator
2230
*/
2331
public function __construct(
2432
Action\Context $context,
25-
\Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
33+
WishlistProviderInterface $wishlistProvider,
34+
Validator $formKeyValidator
2635
) {
2736
$this->wishlistProvider = $wishlistProvider;
37+
$this->formKeyValidator = $formKeyValidator;
2838
parent::__construct($context);
2939
}
3040

@@ -36,6 +46,12 @@ public function __construct(
3646
*/
3747
public function execute()
3848
{
49+
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
50+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
51+
if (!$this->formKeyValidator->validate($this->getRequest())) {
52+
return $resultRedirect->setPath('*/*/');
53+
}
54+
3955
$id = (int)$this->getRequest()->getParam('item');
4056
$item = $this->_objectManager->create('Magento\Wishlist\Model\Item')->load($id);
4157
if (!$item->getId()) {
@@ -68,8 +84,6 @@ public function execute()
6884
} else {
6985
$redirectUrl = $this->_redirect->getRedirectUrl($this->_url->getUrl('*/*'));
7086
}
71-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
72-
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
7387
$resultRedirect->setUrl($redirectUrl);
7488
return $resultRedirect;
7589
}

app/code/Magento/Wishlist/Controller/Index/UpdateItemOptions.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
namespace Magento\Wishlist\Controller\Index;
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Customer\Model\Session;
910
use Magento\Framework\App\Action;
11+
use Magento\Framework\Data\Form\FormKey\Validator;
1012
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\Wishlist\Controller\WishlistProviderInterface;
1215

1316
class UpdateItemOptions extends \Magento\Wishlist\Controller\AbstractIndex
1417
{
1518
/**
16-
* @var \Magento\Wishlist\Controller\WishlistProviderInterface
19+
* @var WishlistProviderInterface
1720
*/
1821
protected $wishlistProvider;
1922

2023
/**
21-
* @var \Magento\Customer\Model\Session
24+
* @var Session
2225
*/
2326
protected $_customerSession;
2427

@@ -27,22 +30,30 @@ class UpdateItemOptions extends \Magento\Wishlist\Controller\AbstractIndex
2730
*/
2831
protected $productRepository;
2932

33+
/**
34+
* @var Validator
35+
*/
36+
protected $formKeyValidator;
37+
3038
/**
3139
* @param Action\Context $context
32-
* @param \Magento\Customer\Model\Session $customerSession
33-
* @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
40+
* @param Session $customerSession
41+
* @param WishlistProviderInterface $wishlistProvider
3442
* @param ProductRepositoryInterface $productRepository
43+
* @param Validator $formKeyValidator
3544
*/
3645
public function __construct(
3746
Action\Context $context,
38-
\Magento\Customer\Model\Session $customerSession,
39-
\Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider,
40-
ProductRepositoryInterface $productRepository
47+
Session $customerSession,
48+
WishlistProviderInterface $wishlistProvider,
49+
ProductRepositoryInterface $productRepository,
50+
Validator $formKeyValidator
4151
) {
4252
$this->_customerSession = $customerSession;
4353
$this->wishlistProvider = $wishlistProvider;
44-
parent::__construct($context);
4554
$this->productRepository = $productRepository;
55+
$this->formKeyValidator = $formKeyValidator;
56+
parent::__construct($context);
4657
}
4758

4859
/**
@@ -52,9 +63,13 @@ public function __construct(
5263
*/
5364
public function execute()
5465
{
55-
$productId = (int)$this->getRequest()->getParam('product');
5666
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
5767
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
68+
if (!$this->formKeyValidator->validate($this->getRequest())) {
69+
return $resultRedirect->setPath('*/*/');
70+
}
71+
72+
$productId = (int)$this->getRequest()->getParam('product');
5873
if (!$productId) {
5974
$resultRedirect->setPath('*/');
6075
return $resultRedirect;

0 commit comments

Comments
 (0)