From c8c4a976237bd6effc8d152c68b3446163fc486c Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Tue, 6 Oct 2015 16:24:27 +0300 Subject: [PATCH 01/10] MAGETWO-41964: Log created on random requests - leads to DoS attack --- .../Store/App/Request/PathInfoProcessor.php | 13 ++- .../Magento/Store/Model/StoreRepository.php | 3 +- .../Magento/Store/Model/StoreResolver.php | 14 +-- .../App/Request/PathInfoProcessorTest.php | 5 +- .../App/Request/PathInfoProcessorTest.php | 106 ++++++++++++++++++ 5 files changed, 120 insertions(+), 21 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php diff --git a/app/code/Magento/Store/App/Request/PathInfoProcessor.php b/app/code/Magento/Store/App/Request/PathInfoProcessor.php index ebe3b64aa3b9c..ef07979226c54 100644 --- a/app/code/Magento/Store/App/Request/PathInfoProcessor.php +++ b/app/code/Magento/Store/App/Request/PathInfoProcessor.php @@ -5,19 +5,21 @@ */ namespace Magento\Store\App\Request; +use Magento\Framework\Exception\NoSuchEntityException; + class PathInfoProcessor implements \Magento\Framework\App\Request\PathInfoProcessorInterface { /** * @var \Magento\Store\Model\StoreManagerInterface */ - private $_storeManager; + private $storeManager; /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager */ public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager) { - $this->_storeManager = $storeManager; + $this->storeManager = $storeManager; } /** @@ -33,14 +35,15 @@ public function process(\Magento\Framework\App\RequestInterface $request, $pathI $storeCode = $pathParts[0]; try { - $store = $this->_storeManager->getStore($storeCode); - } catch (\InvalidArgumentException $e) { // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException + /** @var \Magento\Store\Api\Data\StoreInterface $store */ + $store = $this->storeManager->getStore($storeCode); + } catch (NoSuchEntityException $e) { return $pathInfo; } if ($store->isUseStoreInUrl()) { if (!$request->isDirectAccessFrontendName($storeCode)) { - $this->_storeManager->setCurrentStore($storeCode); + $this->storeManager->setCurrentStore($storeCode); $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); return $pathInfo; } elseif (!empty($storeCode)) { diff --git a/app/code/Magento/Store/Model/StoreRepository.php b/app/code/Magento/Store/Model/StoreRepository.php index 322c358be356f..da72fae5cffee 100644 --- a/app/code/Magento/Store/Model/StoreRepository.php +++ b/app/code/Magento/Store/Model/StoreRepository.php @@ -57,8 +57,7 @@ public function get($code) $store = $this->storeFactory->create(); $store->load($code, 'code'); if ($store->getId() === null) { - // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException - throw new \InvalidArgumentException(); + throw new NoSuchEntityException(); } $this->entities[$code] = $store; $this->entitiesById[$store->getId()] = $store; diff --git a/app/code/Magento/Store/Model/StoreResolver.php b/app/code/Magento/Store/Model/StoreResolver.php index 79a6e53423c79..1f37a8611a277 100644 --- a/app/code/Magento/Store/Model/StoreResolver.php +++ b/app/code/Magento/Store/Model/StoreResolver.php @@ -137,14 +137,9 @@ protected function getRequestedStoreByCode($storeCode) try { $store = $this->storeRepository->getActiveStoreByCode($storeCode); } catch (StoreIsInactiveException $e) { - $error = __('Requested store is inactive'); - } catch (\InvalidArgumentException $e) { // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException - $error = __('Requested store is not found'); + throw new NoSuchEntityException(__('Requested store is inactive')); } - if (isset($error, $e)) { - throw new NoSuchEntityException($error, $e); - } return $store; } @@ -160,14 +155,9 @@ protected function getDefaultStoreById($id) try { $store = $this->storeRepository->getActiveStoreById($id); } catch (StoreIsInactiveException $e) { - $error = __('Default store is inactive'); - } catch (\InvalidArgumentException $e) { // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException - $error = __('Default store is not found'); + throw new NoSuchEntityException(__('Default store is inactive')); } - if (isset($error, $e)) { - throw new NoSuchEntityException($error, $e); - } return $store; } } diff --git a/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php b/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php index b81f0a6544f23..9ba184b950995 100644 --- a/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Store\Test\Unit\App\Request; +use Magento\Framework\Exception\NoSuchEntityException; + class PathInfoProcessorTest extends \PHPUnit_Framework_TestCase { /** @@ -112,8 +114,7 @@ public function testProcessIfStoreCodeIsNotExist() { $store = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $this->_storeManagerMock->expects($this->once())->method('getStore')->with('storeCode') - // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException - ->willThrowException(new \InvalidArgumentException()); + ->willThrowException(new NoSuchEntityException()); $store->expects($this->never())->method('isUseStoreInUrl'); $this->_requestMock->expects($this->never())->method('isDirectAccessFrontendName'); diff --git a/dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php b/dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php new file mode 100644 index 0000000000000..8470436c8bd3e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php @@ -0,0 +1,106 @@ +pathProcessor = Bootstrap::getObjectManager()->create('Magento\Store\App\Request\PathInfoProcessor'); + } + + /** + * @covers \Magento\Store\App\Request\PathInfoProcessor::process + * @dataProvider notValidStoreCodeDataProvider + */ + public function testProcessNotValidStoreCode($pathInfo) + { + /** @var \Magento\Framework\App\RequestInterface $request */ + $request = Bootstrap::getObjectManager()->create('Magento\Framework\App\RequestInterface'); + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); + } + + public function notValidStoreCodeDataProvider() + { + return [ + ['not_valid_store_code_int' => '/100500/m/c/a'], + ['not_valid_store_code_str' => '/test_string/m/c/a'], + ]; + } + + /** + * @covers \Magento\Store\App\Request\PathInfoProcessor::process + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php + */ + public function testProcessValidStoreCodeCase1() + { + /** @var \Magento\Store\Model\Store $store */ + $store = Bootstrap::getObjectManager()->get('Magento\Store\Model\Store'); + $store->load('fixturestore', 'code'); + + /** @var \Magento\Framework\App\RequestInterface $request */ + $request = Bootstrap::getObjectManager()->create('Magento\Framework\App\RequestInterface'); + + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ + $config = Bootstrap::getObjectManager()->get('\Magento\Framework\App\Config\ReinitableConfigInterface'); + $config->setValue(Store::XML_PATH_STORE_IN_URL, false, ScopeInterface::SCOPE_STORE, $store->getCode()); + $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); + } + + /** + * @covers \Magento\Store\App\Request\PathInfoProcessor::process + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php + */ + public function testProcessValidStoreCodeCase2() + { + /** @var \Magento\Store\Model\Store $store */ + $store = Bootstrap::getObjectManager()->get('Magento\Store\Model\Store'); + $store->load('fixturestore', 'code'); + + /** @var \Magento\Framework\App\RequestInterface $request */ + $request = Bootstrap::getObjectManager()->create('Magento\Framework\App\RequestInterface'); + + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ + $config = Bootstrap::getObjectManager()->get('\Magento\Framework\App\Config\ReinitableConfigInterface'); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true, ScopeInterface::SCOPE_STORE, $store->getCode()); + $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); + $this->assertEquals('/m/c/a', $this->pathProcessor->process($request, $pathInfo)); + } + + /** + * @covers \Magento\Store\App\Request\PathInfoProcessor::process + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php + */ + public function testProcessValidStoreCodeCase3() + { + /** @var \Magento\Store\Model\Store $store */ + $store = Bootstrap::getObjectManager()->get('Magento\Store\Model\Store'); + $store->load('fixturestore', 'code'); + + /** @var \Magento\Framework\App\RequestInterface $request */ + $request = Bootstrap::getObjectManager()->create( + 'Magento\Framework\App\RequestInterface', + ['directFrontNames' => [$store->getCode() => true]] + ); + + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ + $config = Bootstrap::getObjectManager()->get('\Magento\Framework\App\Config\ReinitableConfigInterface'); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true, ScopeInterface::SCOPE_STORE, $store->getCode()); + $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); + $this->assertEquals('noroute', $request->getActionName()); + } +} From 0e8eaa1822d98db0e904516c1658c9f6e892a339 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Tue, 6 Oct 2015 16:43:02 +0300 Subject: [PATCH 02/10] MAGETWO-41964: Log created on random requests - leads to DoS attack --- app/code/Magento/Store/Controller/Store/SwitchAction.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Store/Controller/Store/SwitchAction.php b/app/code/Magento/Store/Controller/Store/SwitchAction.php index 647b2cf6c320f..b527b7ad4fe70 100644 --- a/app/code/Magento/Store/Controller/Store/SwitchAction.php +++ b/app/code/Magento/Store/Controller/Store/SwitchAction.php @@ -9,6 +9,7 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context as ActionContext; use Magento\Framework\App\Http\Context as HttpContext; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Store\Api\StoreCookieManagerInterface; use Magento\Store\Api\StoreRepositoryInterface; use Magento\Store\Model\Store; @@ -78,7 +79,7 @@ public function execute() $store = $this->storeRepository->getActiveStoreByCode($storeCode); } catch (StoreIsInactiveException $e) { $error = __('Requested store is inactive'); - } catch (\InvalidArgumentException $e) { + } catch (NoSuchEntityException $e) { $error = __('Requested store is not found'); } From c2f173df231bd2cd6fb1d061ca3b67b5650a7bc8 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Wed, 7 Oct 2015 18:31:21 +0300 Subject: [PATCH 03/10] MAGETWO-41964: Log created on random requests - leads to DoS attack --- app/code/Magento/Store/Model/StoreRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Store/Model/StoreRepository.php b/app/code/Magento/Store/Model/StoreRepository.php index da72fae5cffee..26c466f6cf98b 100644 --- a/app/code/Magento/Store/Model/StoreRepository.php +++ b/app/code/Magento/Store/Model/StoreRepository.php @@ -57,7 +57,7 @@ public function get($code) $store = $this->storeFactory->create(); $store->load($code, 'code'); if ($store->getId() === null) { - throw new NoSuchEntityException(); + throw new NoSuchEntityException(__('Requested store is not found')); } $this->entities[$code] = $store; $this->entitiesById[$store->getId()] = $store; @@ -88,7 +88,7 @@ public function getById($id) $store = $this->storeFactory->create(); $store->load($id); if ($store->getId() === null) { - throw new NoSuchEntityException(); + throw new NoSuchEntityException(__('Requested store is not found')); } $this->entitiesById[$id] = $store; $this->entities[$store->getCode()] = $store; From 437859a645bff0caf76d1b4c3498aec6549998b4 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Thu, 8 Oct 2015 14:45:21 +0300 Subject: [PATCH 04/10] =?UTF-8?q?MAGETWO-43755:=20[GITHUB]=20The=20commit?= =?UTF-8?q?=20=C2=ABPCF:=20removing=20grouped=20price=C2=BB=20from=202015-?= =?UTF-8?q?10-02=20breaks=20Magento=20schema=20upgrading=20with=20the=20ex?= =?UTF-8?q?ception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Magento/Catalog/Setup/UpgradeData.php | 28 +++++++++++-------- .../Magento/Catalog/Setup/UpgradeSchema.php | 4 +++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Catalog/Setup/UpgradeData.php b/app/code/Magento/Catalog/Setup/UpgradeData.php index 5adf385101fc2..a79f0c384aee0 100644 --- a/app/code/Magento/Catalog/Setup/UpgradeData.php +++ b/app/code/Magento/Catalog/Setup/UpgradeData.php @@ -46,21 +46,26 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY); $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId); - $attributeGroupId = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, 'Images'); - - // update General Group - $categorySetup->updateAttributeGroup( + $attributeGroup = $categorySetup->getAttributeGroup( $entityTypeId, $attributeSetId, - $attributeGroupId, - 'attribute_group_name', - 'Images and Videos' + 'Images', + 'attribute_group_name' ); + if ($attributeGroup['attribute_group_name'] == 'Images') { + // update General Group + $categorySetup->updateAttributeGroup( + $entityTypeId, + $attributeSetId, + $attributeGroup['attribute_group_id'], + 'attribute_group_name', + 'Images and Videos' + ); + } $select = $setup->getConnection()->select() ->from( $setup->getTable('catalog_product_entity_group_price'), [ - 'value_id', 'entity_id', 'all_groups', 'customer_group_id', @@ -69,11 +74,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface 'website_id' ] ); - $setup->getConnection()->insertFromSelect( + $select = $setup->getConnection()->insertFromSelect( $select, - $setup->getTable('catalog_product_entity_group_price'), + $setup->getTable('catalog_product_entity_tier_price'), [ - 'value_id', 'entity_id', 'all_groups', 'customer_group_id', @@ -82,6 +86,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface 'website_id' ] ); + $setup->getConnection()->query($select); + $categorySetupManager = $this->categorySetupFactory->create(); $categorySetupManager->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'group_price'); } diff --git a/app/code/Magento/Catalog/Setup/UpgradeSchema.php b/app/code/Magento/Catalog/Setup/UpgradeSchema.php index fe978e80a9807..d54c6e6de4a77 100644 --- a/app/code/Magento/Catalog/Setup/UpgradeSchema.php +++ b/app/code/Magento/Catalog/Setup/UpgradeSchema.php @@ -140,6 +140,10 @@ protected function addForeignKeys(SchemaSetupInterface $setup) */ private function addSupportVideoMediaAttributes(SchemaSetupInterface $setup) { + if ($setup->tableExists(Media::GALLERY_VALUE_TO_ENTITY_TABLE)) { + return; + }; + /** Add support video media attribute */ $this->createValueToEntityTable($setup); /** From d6f3c216e743f52d03ef96d6e1610e75f36c3885 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Thu, 8 Oct 2015 17:38:36 +0300 Subject: [PATCH 05/10] =?UTF-8?q?MAGETWO-43755:=20[GITHUB]=20The=20commit?= =?UTF-8?q?=20=C2=ABPCF:=20removing=20grouped=20price=C2=BB=20from=202015-?= =?UTF-8?q?10-02=20breaks=20Magento=20schema=20upgrading=20with=20the=20ex?= =?UTF-8?q?ception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/code/Magento/Catalog/Setup/UpgradeData.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Setup/UpgradeData.php b/app/code/Magento/Catalog/Setup/UpgradeData.php index a79f0c384aee0..2d09cb6946d70 100644 --- a/app/code/Magento/Catalog/Setup/UpgradeData.php +++ b/app/code/Magento/Catalog/Setup/UpgradeData.php @@ -52,7 +52,9 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface 'Images', 'attribute_group_name' ); - if ($attributeGroup['attribute_group_name'] == 'Images') { + if (isset($attributeGroup['attribute_group_name']) + && $attributeGroup['attribute_group_name'] == 'Images' + ) { // update General Group $categorySetup->updateAttributeGroup( $entityTypeId, From 2aff5a62139373efe41c7bfb55a6736b6c9c1144 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Thu, 8 Oct 2015 17:48:33 +0300 Subject: [PATCH 06/10] =?UTF-8?q?MAGETWO-43755:=20[GITHUB]=20The=20commit?= =?UTF-8?q?=20=C2=ABPCF:=20removing=20grouped=20price=C2=BB=20from=202015-?= =?UTF-8?q?10-02=20breaks=20Magento=20schema=20upgrading=20with=20the=20ex?= =?UTF-8?q?ception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/code/Magento/Catalog/Setup/UpgradeData.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Setup/UpgradeData.php b/app/code/Magento/Catalog/Setup/UpgradeData.php index 2d09cb6946d70..78a0bc035dfb6 100644 --- a/app/code/Magento/Catalog/Setup/UpgradeData.php +++ b/app/code/Magento/Catalog/Setup/UpgradeData.php @@ -39,7 +39,8 @@ public function __construct(CategorySetupFactory $categorySetupFactory) public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - if (version_compare($context->getVersion(), '2.0.1') < 0) { + if ($context->getVersion() && version_compare($context->getVersion(), '2.0.1') < 0) { + /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */ $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); From 0ed510f118ecfb6ef5a734cbe406f5833ddfa0f5 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Thu, 8 Oct 2015 18:15:50 +0300 Subject: [PATCH 07/10] =?UTF-8?q?MAGETWO-43755:=20[GITHUB]=20The=20commit?= =?UTF-8?q?=20=C2=ABPCF:=20removing=20grouped=20price=C2=BB=20from=202015-?= =?UTF-8?q?10-02=20breaks=20Magento=20schema=20upgrading=20with=20the=20ex?= =?UTF-8?q?ception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/code/Magento/Catalog/Setup/UpgradeData.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Setup/UpgradeData.php b/app/code/Magento/Catalog/Setup/UpgradeData.php index 78a0bc035dfb6..4c2d32738e88b 100644 --- a/app/code/Magento/Catalog/Setup/UpgradeData.php +++ b/app/code/Magento/Catalog/Setup/UpgradeData.php @@ -39,8 +39,7 @@ public function __construct(CategorySetupFactory $categorySetupFactory) public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - if ($context->getVersion() && version_compare($context->getVersion(), '2.0.1') < 0) { - + if (version_compare($context->getVersion(), '2.0.1') < 0) { /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */ $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); @@ -53,9 +52,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface 'Images', 'attribute_group_name' ); - if (isset($attributeGroup['attribute_group_name']) - && $attributeGroup['attribute_group_name'] == 'Images' - ) { + if (isset($attributeGroup['attribute_group_name']) && $attributeGroup['attribute_group_name'] == 'Images') { // update General Group $categorySetup->updateAttributeGroup( $entityTypeId, @@ -65,6 +62,11 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface 'Images and Videos' ); } + } + + if ($context->getVersion() + && version_compare($context->getVersion(), '2.0.1') < 0 + ) { $select = $setup->getConnection()->select() ->from( $setup->getTable('catalog_product_entity_group_price'), From 660a35208a406fb5908bc2cdf8702dd34be2a82a Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Fri, 9 Oct 2015 11:17:45 +0300 Subject: [PATCH 08/10] MAGETWO-39604: [GITHUB] Doesn't work sorting in the search list. #1432 --- app/code/Magento/Catalog/Block/Product/ListProduct.php | 2 +- .../Magento/Catalog/Block/Product/ProductList/Toolbar.php | 4 ++-- .../Catalog/view/frontend/web/js/product/list/toolbar.js | 6 ++++-- app/code/Magento/CatalogSearch/Block/Result.php | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Product/ListProduct.php b/app/code/Magento/Catalog/Block/Product/ListProduct.php index 73beec6b2b2e1..c28ab40b55364 100644 --- a/app/code/Magento/Catalog/Block/Product/ListProduct.php +++ b/app/code/Magento/Catalog/Block/Product/ListProduct.php @@ -296,7 +296,7 @@ public function prepareSortableFieldsByCategory($category) } $availableOrders = $this->getAvailableOrders(); if (!$this->getSortBy()) { - $categorySortBy = $category->getDefaultSortBy(); + $categorySortBy = $this->getDefaultSortBy() ?: $category->getDefaultSortBy(); if ($categorySortBy) { if (!$availableOrders) { $availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray(); diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php index 93b34bc6b31ee..cd107905e5fa8 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php @@ -355,7 +355,7 @@ public function removeOrderFromAvailableOrders($order) } /** - * Compare defined order field vith current order field + * Compare defined order field with current order field * * @param string $order * @return bool @@ -375,7 +375,7 @@ public function getPagerUrl($params = []) { $urlParams = []; $urlParams['_current'] = true; - $urlParams['_escape'] = true; + $urlParams['_escape'] = false; $urlParams['_use_rewrite'] = true; $urlParams['_query'] = $params; return $this->getUrl('*/*/*', $urlParams); diff --git a/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js b/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js index 688f836fb1035..5904b567278b7 100644 --- a/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js +++ b/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js @@ -68,7 +68,9 @@ define([ parameters; for (var i = 0; i < urlParams.length; i++) { parameters = urlParams[i].split('='); - paramData[parameters[0]] = parameters[1] !== undefined ? parameters[1] : ''; + paramData[parameters[0]] = parameters[1] !== undefined + ? window.decodeURIComponent(parameters[1].replace(/\+/g, '%20')) + : ''; } paramData[paramName] = paramValue; if (paramValue == defaultValue) { @@ -81,4 +83,4 @@ define([ }); return $.mage.productListToolbarForm; -}); \ No newline at end of file +}); diff --git a/app/code/Magento/CatalogSearch/Block/Result.php b/app/code/Magento/CatalogSearch/Block/Result.php index 4a041db739158..ccd292c7bd0b6 100644 --- a/app/code/Magento/CatalogSearch/Block/Result.php +++ b/app/code/Magento/CatalogSearch/Block/Result.php @@ -133,12 +133,13 @@ public function setListOrders() /* @var $category \Magento\Catalog\Model\Category */ $availableOrders = $category->getAvailableSortByOptions(); unset($availableOrders['position']); + $availableOrders['relevance'] = __('Relevance'); $this->getListBlock()->setAvailableOrders( $availableOrders )->setDefaultDirection( 'desc' - )->setSortBy( + )->setDefaultSortBy( 'relevance' ); From e79be6b96eb474b434881c3501ca9d42b4438075 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Fri, 9 Oct 2015 12:36:46 +0300 Subject: [PATCH 09/10] MAGETWO-43842: test case names have full directory paths in them --- .../Test/Integrity/Modular/AclConfigFilesTest.php | 1 - .../Test/Integrity/Modular/DiConfigFilesTest.php | 2 +- .../Test/Integrity/Modular/IndexerConfigFilesTest.php | 10 +--------- .../Magento/Test/Integrity/Theme/XmlFilesTest.php | 6 +++--- lib/internal/Magento/Framework/App/Utility/Files.php | 2 +- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/AclConfigFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/AclConfigFilesTest.php index 7863c4201bd73..c998094fc963a 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/AclConfigFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/AclConfigFilesTest.php @@ -5,7 +5,6 @@ */ namespace Magento\Test\Integrity\Modular; -use Magento\Framework\App\Filesystem\DirectoryList; class AclConfigFilesTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/DiConfigFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/DiConfigFilesTest.php index 79b6958842878..42b6a74d7e06d 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/DiConfigFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/DiConfigFilesTest.php @@ -92,7 +92,7 @@ public function linearFilesProvider() $output = []; foreach ($common as $path => $file) { - $output[$path] = [$file]; + $output[substr($path, strlen(BP))] = [$file]; } return $output; diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/IndexerConfigFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/IndexerConfigFilesTest.php index 5a330a83dbe83..f12917f9c456d 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/IndexerConfigFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/IndexerConfigFilesTest.php @@ -5,7 +5,6 @@ */ namespace Magento\Test\Integrity\Modular; -use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; class IndexerConfigFilesTest extends \PHPUnit_Framework_TestCase @@ -51,13 +50,6 @@ public function testIndexerConfigFile($file) */ public function indexerConfigFileDataProvider() { - /** @var Filesystem $filesystem */ - $utilityFiles = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get('\Magento\Framework\App\Utility\Files'); - - $utilityFiles->getConfigFiles('indexer.xml'); - - $dataProviderResult = $utilityFiles->getConfigFiles('indexer.xml'); - return $dataProviderResult; + return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('indexer.xml'); } } diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Theme/XmlFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Theme/XmlFilesTest.php index ca81ea4973a09..95a9bb0d8cb7b 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Theme/XmlFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Theme/XmlFilesTest.php @@ -36,7 +36,7 @@ public function viewConfigFileDataProvider() ->get('Magento\Framework\Component\DirSearch'); $files = $componentDirSearch->collectFiles(ComponentRegistrar::THEME, 'etc/view.xml'); foreach ($files as $file) { - $result[$file] = [$file]; + $result[substr($file, strlen(BP))] = [$file]; } return $result; } @@ -60,7 +60,7 @@ public function themeConfigFileExistsDataProvider() $componentRegistrar = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('\Magento\Framework\Component\ComponentRegistrar'); foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themeDir) { - $result[$themeDir] = [$themeDir]; + $result[substr($themeDir, strlen(BP))] = [$themeDir]; } return $result; } @@ -102,7 +102,7 @@ public function themeConfigFileDataProvider() ->get('Magento\Framework\Component\DirSearch'); $files = $componentDirSearch->collectFiles(ComponentRegistrar::THEME, 'theme.xml'); foreach ($files as $file) { - $result[$file] = [$file]; + $result[substr($file, strlen(BP))] = [$file]; } return $result; } diff --git a/lib/internal/Magento/Framework/App/Utility/Files.php b/lib/internal/Magento/Framework/App/Utility/Files.php index e19dd388fc6d3..7802320f6fc32 100644 --- a/lib/internal/Magento/Framework/App/Utility/Files.php +++ b/lib/internal/Magento/Framework/App/Utility/Files.php @@ -106,7 +106,7 @@ public static function composeDataSets(array $files) { $result = []; foreach ($files as $file) { - $result[$file] = [$file]; + $result[substr($file, strlen(BP))] = [$file]; } return $result; } From b1e5ae41b8d2e8400ce012a2b35fa26167d62bd3 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Tue, 13 Oct 2015 15:14:47 +0300 Subject: [PATCH 10/10] MAGETWO-39604: [GITHUB] Doesn't work sorting in the search list. #1432 --- .../Catalog/Block/Product/ProductList/Toolbar.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php index 7188c99efea71..4661cfb7110c2 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php @@ -5,6 +5,7 @@ */ namespace Magento\Catalog\Block\Product\ProductList; +use Magento\Catalog\Helper\Product\ProductList; use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel; /** @@ -63,7 +64,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template * * @var string */ - protected $_direction = \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION; + protected $_direction = ProductList::DEFAULT_SORT_DIRECTION; /** * Default View mode @@ -102,7 +103,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template protected $_toolbarModel; /** - * @var \Magento\Catalog\Helper\Product\ProductList + * @var ProductList */ protected $_productListHelper; @@ -122,7 +123,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template * @param \Magento\Catalog\Model\Config $catalogConfig * @param ToolbarModel $toolbarModel * @param \Magento\Framework\Url\EncoderInterface $urlEncoder - * @param \Magento\Catalog\Helper\Product\ProductList $productListHelper + * @param ProductList $productListHelper * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper * @param array $data */ @@ -132,7 +133,7 @@ public function __construct( \Magento\Catalog\Model\Config $catalogConfig, ToolbarModel $toolbarModel, \Magento\Framework\Url\EncoderInterface $urlEncoder, - \Magento\Catalog\Helper\Product\ProductList $productListHelper, + ProductList $productListHelper, \Magento\Framework\Data\Helper\PostHelper $postDataHelper, array $data = [] ) { @@ -678,7 +679,7 @@ public function getWidgetOptionsJson(array $customOptions = []) 'order' => ToolbarModel::ORDER_PARAM_NAME, 'limit' => ToolbarModel::LIMIT_PARAM_NAME, 'modeDefault' => $defaultMode, - 'directionDefault' => \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION, + 'directionDefault' => $this->_direction ?: ProductList::DEFAULT_SORT_DIRECTION, 'orderDefault' => $this->_productListHelper->getDefaultSortField(), 'limitDefault' => $this->_productListHelper->getDefaultLimitPerPageValue($defaultMode), 'url' => $this->getPagerUrl(),