Skip to content

Commit 814e992

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.3-develop' into MAGETWO-90632
2 parents 2d1bf31 + 827d2d4 commit 814e992

File tree

256 files changed

+10943
-2653
lines changed

Some content is hidden

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

256 files changed

+10943
-2653
lines changed

app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
namespace Magento\AdvancedSearch\Model\ResourceModel;
77

88
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
9+
use Magento\Framework\Search\Request\IndexScopeResolverInterface;
910
use Magento\Store\Model\StoreManagerInterface;
1011
use Magento\Framework\Model\ResourceModel\Db\Context;
1112
use Magento\Framework\EntityManager\MetadataPool;
1213
use Magento\Catalog\Api\Data\CategoryInterface;
1314
use Magento\Framework\App\ObjectManager;
14-
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver as TableResolver;
1515
use Magento\Framework\Search\Request\Dimension;
1616
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
17+
use Magento\Framework\Search\Request\IndexScopeResolverInterface as TableResolver;
18+
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
1719

1820
/**
1921
* @api
2022
* @since 100.1.0
23+
*
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2125
*/
2226
class Index extends AbstractDb
2327
{
@@ -38,25 +42,34 @@ class Index extends AbstractDb
3842
*/
3943
private $tableResolver;
4044

45+
/**
46+
* @var DimensionCollectionFactory|null
47+
*/
48+
private $dimensionCollectionFactory;
49+
4150
/**
4251
* Index constructor.
4352
* @param Context $context
4453
* @param StoreManagerInterface $storeManager
4554
* @param MetadataPool $metadataPool
4655
* @param null $connectionName
4756
* @param TableResolver|null $tableResolver
57+
* @param DimensionCollectionFactory|null $dimensionCollectionFactory
4858
*/
4959
public function __construct(
5060
Context $context,
5161
StoreManagerInterface $storeManager,
5262
MetadataPool $metadataPool,
5363
$connectionName = null,
54-
TableResolver $tableResolver = null
64+
TableResolver $tableResolver = null,
65+
DimensionCollectionFactory $dimensionCollectionFactory = null
5566
) {
5667
parent::__construct($context, $connectionName);
5768
$this->storeManager = $storeManager;
5869
$this->metadataPool = $metadataPool;
59-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
70+
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(IndexScopeResolverInterface::class);
71+
$this->dimensionCollectionFactory = $dimensionCollectionFactory
72+
?: ObjectManager::getInstance()->get(DimensionCollectionFactory::class);
6073
}
6174

6275
/**
@@ -78,18 +91,22 @@ protected function _construct()
7891
protected function _getCatalogProductPriceData($productIds = null)
7992
{
8093
$connection = $this->getConnection();
81-
82-
$select = $connection->select()->from(
83-
$this->getTable('catalog_product_index_price'),
84-
['entity_id', 'customer_group_id', 'website_id', 'min_price']
85-
);
86-
87-
if ($productIds) {
88-
$select->where('entity_id IN (?)', $productIds);
94+
$catalogProductIndexPriceSelect = [];
95+
96+
foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
97+
$catalogProductIndexPriceSelect[] = $connection->select()->from(
98+
$this->tableResolver->resolve('catalog_product_index_price', $dimensions),
99+
['entity_id', 'customer_group_id', 'website_id', 'min_price']
100+
);
101+
if ($productIds) {
102+
current($catalogProductIndexPriceSelect)->where('entity_id IN (?)', $productIds);
103+
}
89104
}
90105

106+
$catalogProductIndexPriceUnionSelect = $connection->select()->union($catalogProductIndexPriceSelect);
107+
91108
$result = [];
92-
foreach ($connection->fetchAll($select) as $row) {
109+
foreach ($connection->fetchAll($catalogProductIndexPriceUnionSelect) as $row) {
93110
$result[$row['website_id']][$row['entity_id']][$row['customer_group_id']] = round($row['min_price'], 2);
94111
}
95112

app/code/Magento/AdvancedSearch/Test/Unit/Model/ResourceModel/IndexTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Magento\Framework\App\ResourceConnection;
1616
use Magento\Framework\DB\Select;
1717

18+
/**
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20+
*/
1821
class IndexTest extends \PHPUnit\Framework\TestCase
1922
{
2023
/**
@@ -59,10 +62,24 @@ protected function setUp()
5962
$this->resourceConnectionMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
6063
$this->metadataPoolMock = $this->createMock(MetadataPool::class);
6164

65+
$indexScopeResolverMock = $this->createMock(
66+
\Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver::class
67+
);
68+
$traversableMock = $this->createMock(\Traversable::class);
69+
$dimensionsMock = $this->createMock(\Magento\Framework\Indexer\MultiDimensionProvider::class);
70+
$dimensionsMock->method('getIterator')->willReturn($traversableMock);
71+
$dimensionFactoryMock = $this->createMock(
72+
\Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory::class
73+
);
74+
$dimensionFactoryMock->method('create')->willReturn($dimensionsMock);
75+
6276
$this->model = new Index(
6377
$this->resourceContextMock,
6478
$this->storeManagerMock,
65-
$this->metadataPoolMock
79+
$this->metadataPoolMock,
80+
'connectionName',
81+
$indexScopeResolverMock,
82+
$dimensionFactoryMock
6683
);
6784
}
6885

@@ -71,11 +88,13 @@ public function testGetPriceIndexDataUsesFrontendPriceIndexerTable()
7188
$storeId = 1;
7289
$storeMock = $this->createMock(StoreInterface::class);
7390
$storeMock->expects($this->any())->method('getId')->willReturn($storeId);
91+
$storeMock->method('getWebsiteId')->willReturn(1);
7492
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock);
7593

7694
$selectMock = $this->createMock(Select::class);
7795
$selectMock->expects($this->any())->method('from')->willReturnSelf();
7896
$selectMock->expects($this->any())->method('where')->willReturnSelf();
97+
$selectMock->expects($this->any())->method('union')->willReturnSelf();
7998
$this->adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
8099
$this->adapterMock->expects($this->once())->method('fetchAll')->with($selectMock)->willReturn([]);
81100

app/code/Magento/AdvancedSearch/etc/di.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,25 @@
1919
<argument name="title" xsi:type="string" translatable="true">Did you mean</argument>
2020
</arguments>
2121
</type>
22+
<type name="Magento\AdvancedSearch\Model\Client\ClientResolver">
23+
<arguments>
24+
<argument name="path" xsi:type="const">Magento\CatalogSearch\Model\ResourceModel\EngineInterface::CONFIG_ENGINE_PATH</argument>
25+
<argument name="scopeType" xsi:type="const">\Magento\Store\Model\ScopeInterface::SCOPE_STORE</argument>
26+
</arguments>
27+
</type>
2228
<type name="Magento\AdvancedSearch\Model\SuggestedQueries">
2329
<arguments>
2430
<argument name="data" xsi:type="array">
2531
<item name="mysql" xsi:type="string">Magento\AdvancedSearch\Model\DataProvider\Suggestions</item>
2632
</argument>
2733
</arguments>
2834
</type>
35+
<type name="Magento\AdvancedSearch\Model\ResourceModel\Index">
36+
<arguments>
37+
<argument name="tableResolver" xsi:type="object">
38+
Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver
39+
</argument>
40+
</arguments>
41+
</type>
2942
<preference for="Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProviderInterface" type="Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProvider" />
3043
</config>

app/code/Magento/Captcha/Model/Customer/Plugin/AjaxLogin.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Captcha\Model\Customer\Plugin;
78

89
use Magento\Captcha\Helper\Data as CaptchaHelper;
@@ -81,27 +82,37 @@ public function aroundExecute(
8182
if ($content) {
8283
$loginParams = $this->serializer->unserialize($content);
8384
}
84-
$username = isset($loginParams['username']) ? $loginParams['username'] : null;
85-
$captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
86-
$loginFormId = isset($loginParams[$captchaFormIdField]) ? $loginParams[$captchaFormIdField] : null;
85+
$username = $loginParams['username'] ?? null;
86+
$captchaString = $loginParams[$captchaInputName] ?? null;
87+
$loginFormId = $loginParams[$captchaFormIdField] ?? null;
8788

88-
foreach ($this->formIds as $formId) {
89-
$captchaModel = $this->helper->getCaptcha($formId);
90-
if ($captchaModel->isRequired($username) && !in_array($loginFormId, $this->formIds)) {
91-
$resultJson = $this->resultJsonFactory->create();
92-
return $resultJson->setData(['errors' => true, 'message' => __('Provided form does not exist')]);
93-
}
89+
if (!in_array($loginFormId, $this->formIds) && $this->helper->getCaptcha($loginFormId)->isRequired($username)) {
90+
return $this->returnJsonError(__('Provided form does not exist'));
91+
}
9492

95-
if ($formId == $loginFormId) {
96-
$captchaModel->logAttempt($username);
97-
if (!$captchaModel->isCorrect($captchaString)) {
98-
$this->sessionManager->setUsername($username);
99-
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
100-
$resultJson = $this->resultJsonFactory->create();
101-
return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
93+
foreach ($this->formIds as $formId) {
94+
if ($formId === $loginFormId) {
95+
$captchaModel = $this->helper->getCaptcha($formId);
96+
if ($captchaModel->isRequired($username)) {
97+
$captchaModel->logAttempt($username);
98+
if (!$captchaModel->isCorrect($captchaString)) {
99+
$this->sessionManager->setUsername($username);
100+
return $this->returnJsonError(__('Incorrect CAPTCHA'));
101+
}
102102
}
103103
}
104104
}
105105
return $proceed();
106106
}
107+
108+
/**
109+
*
110+
* @param \Magento\Framework\Phrase $phrase
111+
* @return \Magento\Framework\Controller\Result\Json
112+
*/
113+
private function returnJsonError(\Magento\Framework\Phrase $phrase): \Magento\Framework\Controller\Result\Json
114+
{
115+
$resultJson = $this->resultJsonFactory->create();
116+
return $resultJson->setData(['errors' => true, 'message' => $phrase]);
117+
}
107118
}

app/code/Magento/Captcha/Model/DefaultModel.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Captcha\Model;
77

8+
use Magento\Captcha\Helper\Data;
9+
810
/**
911
* Implementation of \Zend\Captcha\Image
1012
*
@@ -29,7 +31,7 @@ class DefaultModel extends \Zend\Captcha\Image implements \Magento\Captcha\Model
2931
const DEFAULT_WORD_LENGTH_TO = 5;
3032

3133
/**
32-
* @var \Magento\Captcha\Helper\Data
34+
* @var Data
3335
* @since 100.2.0
3436
*/
3537
protected $captchaData;
@@ -125,8 +127,8 @@ public function getBlockName()
125127
*/
126128
public function isRequired($login = null)
127129
{
128-
if ($this->isUserAuth()
129-
&& !$this->isShownToLoggedInUser()
130+
if (($this->isUserAuth()
131+
&& !$this->isShownToLoggedInUser())
130132
|| !$this->isEnabled()
131133
|| !in_array(
132134
$this->formId,
@@ -431,12 +433,14 @@ public function getWordLen()
431433
*/
432434
private function isShowAlways()
433435
{
434-
if ((string)$this->captchaData->getConfig('mode') == \Magento\Captcha\Helper\Data::MODE_ALWAYS) {
436+
$captchaMode = (string)$this->captchaData->getConfig('mode');
437+
438+
if ($captchaMode === Data::MODE_ALWAYS) {
435439
return true;
436440
}
437441

438-
if ((string)$this->captchaData->getConfig('mode') == \Magento\Captcha\Helper\Data::MODE_AFTER_FAIL
439-
&& $this->getAllowedAttemptsForSameLogin() == 0
442+
if ($captchaMode === Data::MODE_AFTER_FAIL
443+
&& $this->getAllowedAttemptsForSameLogin() === 0
440444
) {
441445
return true;
442446
}

0 commit comments

Comments
 (0)