Skip to content

Commit 60fcebc

Browse files
author
Oleksii Korshenko
committed
MAGETWO-58923: Functional Improvements for Magento 2.0.10
1 parent ea78f5c commit 60fcebc

File tree

63 files changed

+1750
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1750
-160
lines changed

app/bootstrap.php

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
$mask = file_exists($umaskFile) ? octdec(file_get_contents($umaskFile)) : 002;
3636
umask($mask);
3737

38+
if (empty($_SERVER['ENABLE_IIS_REWRITES']) || ($_SERVER['ENABLE_IIS_REWRITES'] != 1)) {
39+
/*
40+
* Unset headers used by IIS URL rewrites.
41+
*/
42+
unset($_SERVER['HTTP_X_REWRITE_URL']);
43+
unset($_SERVER['HTTP_X_ORIGINAL_URL']);
44+
unset($_SERVER['IIS_WasUrlRewritten']);
45+
unset($_SERVER['UNENCODED_URL']);
46+
unset($_SERVER['ORIG_PATH_INFO']);
47+
}
48+
3849
if (!empty($_SERVER['MAGE_PROFILER'])
3950
&& isset($_SERVER['HTTP_ACCEPT'])
4051
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false

app/code/Magento/Backend/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"magento/framework": "100.0.*"
2222
},
2323
"type": "magento2-module",
24-
"version": "100.0.7",
24+
"version": "100.0.8",
2525
"license": [
2626
"OSL-3.0",
2727
"AFL-3.0"

app/code/Magento/Braintree/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"magento/module-checkout-agreements": "100.0.*"
2323
},
2424
"type": "magento2-module",
25-
"version": "100.0.6",
25+
"version": "100.0.7",
2626
"license": [
2727
"proprietary"
2828
],

app/code/Magento/Catalog/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"magento/module-catalog-sample-data": "Sample Data version:100.0.*"
3535
},
3636
"type": "magento2-module",
37-
"version": "100.0.9",
37+
"version": "100.0.10",
3838
"license": [
3939
"OSL-3.0",
4040
"AFL-3.0"

app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php

+30
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
use Magento\Framework\Json\Helper\Data;
1414
use Magento\Framework\View\Result\PageFactory;
1515
use Psr\Log\LoggerInterface;
16+
use Magento\Framework\Data\Form\FormKey\Validator;
17+
use Magento\Framework\App\ObjectManager;
1618

19+
/**
20+
* Class RemoveItem
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
*/
1723
class RemoveItem extends Action
1824
{
1925
/**
@@ -36,6 +42,11 @@ class RemoveItem extends Action
3642
*/
3743
protected $resultPageFactory;
3844

45+
/**
46+
* @var Validator
47+
*/
48+
private $formKeyValidator;
49+
3950
/**
4051
* @param Context $context
4152
* @param Sidebar $sidebar
@@ -59,12 +70,17 @@ public function __construct(
5970
}
6071

6172
/**
73+
* Executes the main action of the controller
74+
*
6275
* @return $this
6376
*/
6477
public function execute()
6578
{
6679
$itemId = (int)$this->getRequest()->getParam('item_id');
6780
try {
81+
if (!$this->getFormKeyValidator()->validate($this->getRequest())) {
82+
throw new LocalizedException(__('We can\'t remove the item.'));
83+
}
6884
$this->sidebar->checkQuoteItem($itemId);
6985
$this->sidebar->removeQuoteItem($itemId);
7086
return $this->jsonResponse();
@@ -90,4 +106,18 @@ protected function jsonResponse($error = '')
90106
$this->jsonHelper->jsonEncode($response)
91107
);
92108
}
109+
110+
/**
111+
* Getter for FormKeyValidator
112+
*
113+
* @deprecated
114+
* @return Validator
115+
*/
116+
private function getFormKeyValidator()
117+
{
118+
if ($this->formKeyValidator === null) {
119+
$this->formKeyValidator = ObjectManager::getInstance()->get(Validator::class);
120+
}
121+
return $this->formKeyValidator;
122+
}
93123
}

app/code/Magento/Checkout/Controller/Sidebar/UpdateItemQty.php

+30
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Framework\Json\Helper\Data;
1414
use Psr\Log\LoggerInterface;
15+
use Magento\Framework\Data\Form\FormKey\Validator;
16+
use \Magento\Framework\App\ObjectManager;
1517

18+
/**
19+
* Class UpdateItemQty
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
*/
1622
class UpdateItemQty extends Action
1723
{
1824
/**
@@ -30,6 +36,11 @@ class UpdateItemQty extends Action
3036
*/
3137
protected $jsonHelper;
3238

39+
/**
40+
* @var Validator
41+
*/
42+
private $formKeyValidator;
43+
3344
/**
3445
* @param Context $context
3546
* @param Sidebar $sidebar
@@ -50,6 +61,8 @@ public function __construct(
5061
}
5162

5263
/**
64+
* Executes the main action of the controller
65+
*
5366
* @return $this
5467
*/
5568
public function execute()
@@ -58,6 +71,9 @@ public function execute()
5871
$itemQty = (int)$this->getRequest()->getParam('item_qty');
5972

6073
try {
74+
if (!$this->getFormKeyValidator()->validate($this->getRequest())) {
75+
throw new LocalizedException(__('We can\'t update the shopping cart.'));
76+
}
6177
$this->sidebar->checkQuoteItem($itemId);
6278
$this->sidebar->updateQuoteItem($itemId, $itemQty);
6379
return $this->jsonResponse();
@@ -81,4 +97,18 @@ protected function jsonResponse($error = '')
8197
$this->jsonHelper->jsonEncode($this->sidebar->getResponseData($error))
8298
);
8399
}
100+
101+
/**
102+
* Getter for FormKeyValidator
103+
*
104+
* @deprecated
105+
* @return Validator
106+
*/
107+
private function getFormKeyValidator()
108+
{
109+
if ($this->formKeyValidator === null) {
110+
$this->formKeyValidator = ObjectManager::getInstance()->get(Validator::class);
111+
}
112+
return $this->formKeyValidator;
113+
}
84114
}

app/code/Magento/Checkout/Model/Cart.php

+28-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Catalog\Model\Product;
1010
use Magento\Checkout\Model\Cart\CartInterface;
11-
use Magento\Framework\Exception\NoSuchEntityException;
1211
use Magento\Framework\DataObject;
12+
use Magento\Framework\Exception\NoSuchEntityException;
1313

1414
/**
1515
* Shopping cart model
@@ -90,6 +90,11 @@ class Cart extends DataObject implements CartInterface
9090
*/
9191
protected $productRepository;
9292

93+
/**
94+
* @var \Magento\Checkout\Model\Cart\RequestInfoFilterInterface
95+
*/
96+
private $requestInfoFilter;
97+
9398
/**
9499
* @param \Magento\Framework\Event\ManagerInterface $eventManager
95100
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -310,22 +315,27 @@ protected function _getProduct($productInfo)
310315
*
311316
* @param \Magento\Framework\DataObject|int|array $requestInfo
312317
* @return \Magento\Framework\DataObject
318+
* @throws \Magento\Framework\Exception\LocalizedException
313319
*/
314320
protected function _getProductRequest($requestInfo)
315321
{
316322
if ($requestInfo instanceof \Magento\Framework\DataObject) {
317323
$request = $requestInfo;
318324
} elseif (is_numeric($requestInfo)) {
319325
$request = new \Magento\Framework\DataObject(['qty' => $requestInfo]);
320-
} else {
326+
} elseif (is_array($requestInfo)) {
321327
$request = new \Magento\Framework\DataObject($requestInfo);
328+
} else {
329+
throw new \Magento\Framework\Exception\LocalizedException(
330+
__('We found an invalid request for adding product to quote.')
331+
);
322332
}
323333

324334
if (!$request->hasQty()) {
325335
$request->setQty(1);
326336
}
327-
!$request->hasFormKey() ?: $request->unsFormKey();
328337

338+
$this->getRequestInfoFilter()->filter($request);
329339
return $request;
330340
}
331341

@@ -720,4 +730,19 @@ public function updateItem($itemId, $requestInfo = null, $updatingParams = null)
720730
$this->_checkoutSession->setLastAddedProductId($productId);
721731
return $result;
722732
}
733+
734+
/**
735+
* Getter for RequestInfoFilter
736+
*
737+
* @deprecated
738+
* @return \Magento\Checkout\Model\Cart\RequestInfoFilterInterface
739+
*/
740+
private function getRequestInfoFilter()
741+
{
742+
if ($this->requestInfoFilter === null) {
743+
$this->requestInfoFilter = \Magento\Framework\App\ObjectManager::getInstance()
744+
->get(\Magento\Checkout\Model\Cart\RequestInfoFilterInterface::class);
745+
}
746+
return $this->requestInfoFilter;
747+
}
723748
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Checkout\Model\Cart;
8+
9+
/**
10+
* Class RequestInfoFilter used for filtering data from a request
11+
*/
12+
class RequestInfoFilter implements RequestInfoFilterInterface
13+
{
14+
/**
15+
* @var array $params
16+
*/
17+
private $filterList;
18+
19+
/**
20+
* @param array $filterList
21+
*/
22+
public function __construct(
23+
array $filterList = []
24+
) {
25+
$this->filterList = $filterList;
26+
}
27+
28+
/**
29+
* Filters the data with values from filterList
30+
*
31+
* @param \Magento\Framework\DataObject $params
32+
* @return $this
33+
*/
34+
public function filter(\Magento\Framework\DataObject $params)
35+
{
36+
foreach ($this->filterList as $filterKey) {
37+
/** @var string $filterKey */
38+
if ($params->hasData($filterKey)) {
39+
$params->unsetData($filterKey);
40+
}
41+
}
42+
return $this;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Checkout\Model\Cart;
8+
9+
/**
10+
* Class RequestInfoFilterComposite
11+
*/
12+
class RequestInfoFilterComposite implements RequestInfoFilterInterface
13+
{
14+
/**
15+
* @var RequestInfoFilter[] $params
16+
*/
17+
private $filters = [];
18+
19+
/**
20+
* @param RequestInfoFilter[] $filters
21+
*/
22+
public function __construct(
23+
$filters = []
24+
) {
25+
$this->filters = $filters;
26+
}
27+
28+
/**
29+
* Loops through all leafs of the composite and calls filter method
30+
*
31+
* @param \Magento\Framework\DataObject $params
32+
* @return $this
33+
*/
34+
public function filter(\Magento\Framework\DataObject $params)
35+
{
36+
foreach ($this->filters as $filter) {
37+
$filter->filter($params);
38+
}
39+
return $this;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Checkout\Model\Cart;
8+
9+
/**
10+
* Interface RequestInfoFilterInterface used by composite and leafs to implement filtering
11+
*/
12+
interface RequestInfoFilterInterface
13+
{
14+
/**
15+
* Filters the data object by an array of parameters
16+
*
17+
* @param \Magento\Framework\DataObject $params
18+
* @return RequestInfoFilterInterface
19+
*/
20+
public function filter(\Magento\Framework\DataObject $params);
21+
}

0 commit comments

Comments
 (0)