Skip to content

Commit 7964e7c

Browse files
committed
Merge branch '2.3-develop' of https://github.com/magento/magento2ce into MAGETWO-97495
2 parents 1f78b97 + 46a307e commit 7964e7c

File tree

19 files changed

+457
-273
lines changed

19 files changed

+457
-273
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
use Magento\Framework\EntityManager\MetadataPool;
1111

1212
/**
13-
* Class FlatTableBuilder
13+
* Class for building flat index
14+
*
1415
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1516
*/
1617
class FlatTableBuilder
@@ -346,12 +347,21 @@ protected function _updateTemporaryTableByStoreValues(
346347
}
347348

348349
//Update not simple attributes (eg. dropdown)
349-
if (isset($flatColumns[$attributeCode . $valueFieldSuffix])) {
350-
$select = $this->_connection->select()->joinInner(
351-
['t' => $this->_productIndexerHelper->getTable('eav_attribute_option_value')],
352-
't.option_id = et.' . $attributeCode . ' AND t.store_id=' . $storeId,
353-
[$attributeCode . $valueFieldSuffix => 't.value']
354-
);
350+
$columnName = $attributeCode . $valueFieldSuffix;
351+
if (isset($flatColumns[$columnName])) {
352+
$columnValue = $this->_connection->getIfNullSql('ts.value', 't0.value');
353+
$select = $this->_connection->select();
354+
$select->joinLeft(
355+
['t0' => $this->_productIndexerHelper->getTable('eav_attribute_option_value')],
356+
't0.option_id = et.' . $attributeCode . ' AND t0.store_id = 0',
357+
[]
358+
)->joinLeft(
359+
['ts' => $this->_productIndexerHelper->getTable('eav_attribute_option_value')],
360+
'ts.option_id = et.' . $attributeCode . ' AND ts.store_id = ' . $storeId,
361+
[]
362+
)->columns(
363+
[$columnName => $columnValue]
364+
)->where($columnValue . ' IS NOT NULL');
355365
if (!empty($changedIds)) {
356366
$select->where($this->_connection->quoteInto('et.entity_id IN (?)', $changedIds));
357367
}
@@ -374,6 +384,8 @@ protected function _getTemporaryTableName($tableName)
374384
}
375385

376386
/**
387+
* Get metadata pool
388+
*
377389
* @return \Magento\Framework\EntityManager\MetadataPool
378390
*/
379391
private function getMetadataPool()

app/code/Magento/CatalogSearch/Model/Layer/Filter/Attribute.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@ protected function _getItemsData()
9191
return $this->itemDataBuilder->build();
9292
}
9393

94-
$productSize = $productCollection->getSize();
95-
9694
$options = $attribute->getFrontend()
9795
->getSelectOptions();
9896
foreach ($options as $option) {
99-
$this->buildOptionData($option, $isAttributeFilterable, $optionsFacetedData, $productSize);
97+
$this->buildOptionData($option, $isAttributeFilterable, $optionsFacetedData);
10098
}
10199

102100
return $this->itemDataBuilder->build();
@@ -108,17 +106,16 @@ protected function _getItemsData()
108106
* @param array $option
109107
* @param boolean $isAttributeFilterable
110108
* @param array $optionsFacetedData
111-
* @param int $productSize
112109
* @return void
113110
*/
114-
private function buildOptionData($option, $isAttributeFilterable, $optionsFacetedData, $productSize)
111+
private function buildOptionData($option, $isAttributeFilterable, $optionsFacetedData)
115112
{
116113
$value = $this->getOptionValue($option);
117114
if ($value === false) {
118115
return;
119116
}
120117
$count = $this->getOptionCount($value, $optionsFacetedData);
121-
if ($isAttributeFilterable && (!$this->isOptionReducesResults($count, $productSize) || $count === 0)) {
118+
if ($isAttributeFilterable && $count === 0) {
122119
return;
123120
}
124121

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/AttributeTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ public function testGetItemsWithoutApply()
321321
->method('build')
322322
->will($this->returnValue($builtData));
323323

324-
$this->fulltextCollection->expects($this->once())
325-
->method('getSize')
326-
->will($this->returnValue(50));
327-
328324
$expectedFilterItems = [
329325
$this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count']),
330326
$this->createFilterItem(1, $builtData[1]['label'], $builtData[1]['value'], $builtData[1]['count']),
@@ -383,9 +379,6 @@ public function testGetItemsOnlyWithResults()
383379
$this->fulltextCollection->expects($this->once())
384380
->method('getFacetedData')
385381
->willReturn($facetedData);
386-
$this->fulltextCollection->expects($this->once())
387-
->method('getSize')
388-
->will($this->returnValue(50));
389382

390383
$this->itemDataBuilder->expects($this->once())
391384
->method('addItemData')

app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77

88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Console\Command\ConfigSetCommand;
10+
use Magento\Config\Model\Config\Factory as ConfigFactory;
1011
use Magento\Framework\App\Config\ConfigPathResolver;
1112
use Magento\Framework\App\DeploymentConfig;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Exception\CouldNotSaveException;
1315
use Magento\Config\Model\PreparedValueFactory;
14-
use Magento\Framework\App\Config\Value;
1516

1617
/**
1718
* Processes default flow of config:set command.
19+
*
1820
* This processor saves the value of configuration into database.
1921
*
20-
* {@inheritdoc}
22+
* @inheritdoc
2123
* @api
2224
* @since 100.2.0
2325
*/
@@ -44,26 +46,36 @@ class DefaultProcessor implements ConfigSetProcessorInterface
4446
*/
4547
private $preparedValueFactory;
4648

49+
/**
50+
* @var ConfigFactory
51+
*/
52+
private $configFactory;
53+
4754
/**
4855
* @param PreparedValueFactory $preparedValueFactory The factory for prepared value
4956
* @param DeploymentConfig $deploymentConfig The deployment configuration reader
5057
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths according to source type
58+
* @param ConfigFactory|null $configFactory
5159
*/
5260
public function __construct(
5361
PreparedValueFactory $preparedValueFactory,
5462
DeploymentConfig $deploymentConfig,
55-
ConfigPathResolver $configPathResolver
63+
ConfigPathResolver $configPathResolver,
64+
ConfigFactory $configFactory = null
5665
) {
5766
$this->preparedValueFactory = $preparedValueFactory;
5867
$this->deploymentConfig = $deploymentConfig;
5968
$this->configPathResolver = $configPathResolver;
69+
70+
$this->configFactory = $configFactory ?? ObjectManager::getInstance()->get(ConfigFactory::class);
6071
}
6172

6273
/**
6374
* Processes database flow of config:set command.
75+
*
6476
* Requires installed application.
6577
*
66-
* {@inheritdoc}
78+
* @inheritdoc
6779
* @since 100.2.0
6880
*/
6981
public function process($path, $value, $scope, $scopeCode)
@@ -78,12 +90,12 @@ public function process($path, $value, $scope, $scopeCode)
7890
}
7991

8092
try {
81-
/** @var Value $backendModel */
82-
$backendModel = $this->preparedValueFactory->create($path, $value, $scope, $scopeCode);
83-
if ($backendModel instanceof Value) {
84-
$resourceModel = $backendModel->getResource();
85-
$resourceModel->save($backendModel);
86-
}
93+
$config = $this->configFactory->create([
94+
'scope' => $scope,
95+
'scope_code' => $scopeCode,
96+
]);
97+
$config->setDataByPath($path, $value);
98+
$config->save();
8799
} catch (\Exception $exception) {
88100
throw new CouldNotSaveException(__('%1', $exception->getMessage()), $exception);
89101
}

app/code/Magento/Config/Model/Config.php

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@
99
use Magento\Config\Model\Config\Structure\Element\Group;
1010
use Magento\Config\Model\Config\Structure\Element\Field;
1111
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\App\ScopeInterface;
13+
use Magento\Framework\App\ScopeResolverPool;
14+
use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
15+
use Magento\Store\Model\ScopeTypeNormalizer;
1216

1317
/**
1418
* Backend config model
1519
*
1620
* Used to save configuration
21+
*
1722
* @author Magento Core Team <[email protected]>
1823
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1924
* @api
2025
* @since 100.0.2
26+
* @method string getSection()
27+
* @method void setSection(string $section)
28+
* @method string getWebsite()
29+
* @method void setWebsite(string $website)
30+
* @method string getStore()
31+
* @method void setStore(string $store)
32+
* @method string getScope()
33+
* @method void setScope(string $scope)
34+
* @method int getScopeId()
35+
* @method void setScopeId(int $scopeId)
36+
* @method string getScopeCode()
37+
* @method void setScopeCode(string $scopeCode)
2138
*/
2239
class Config extends \Magento\Framework\DataObject
2340
{
@@ -87,6 +104,16 @@ class Config extends \Magento\Framework\DataObject
87104
*/
88105
private $settingChecker;
89106

107+
/**
108+
* @var ScopeResolverPool
109+
*/
110+
private $scopeResolverPool;
111+
112+
/**
113+
* @var ScopeTypeNormalizer
114+
*/
115+
private $scopeTypeNormalizer;
116+
90117
/**
91118
* @param \Magento\Framework\App\Config\ReinitableConfigInterface $config
92119
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -97,6 +124,9 @@ class Config extends \Magento\Framework\DataObject
97124
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
98125
* @param Config\Reader\Source\Deployed\SettingChecker|null $settingChecker
99126
* @param array $data
127+
* @param ScopeResolverPool|null $scopeResolverPool
128+
* @param ScopeTypeNormalizer|null $scopeTypeNormalizer
129+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
100130
*/
101131
public function __construct(
102132
\Magento\Framework\App\Config\ReinitableConfigInterface $config,
@@ -107,7 +137,9 @@ public function __construct(
107137
\Magento\Framework\App\Config\ValueFactory $configValueFactory,
108138
\Magento\Store\Model\StoreManagerInterface $storeManager,
109139
SettingChecker $settingChecker = null,
110-
array $data = []
140+
array $data = [],
141+
ScopeResolverPool $scopeResolverPool = null,
142+
ScopeTypeNormalizer $scopeTypeNormalizer = null
111143
) {
112144
parent::__construct($data);
113145
$this->_eventManager = $eventManager;
@@ -117,7 +149,12 @@ public function __construct(
117149
$this->_configLoader = $configLoader;
118150
$this->_configValueFactory = $configValueFactory;
119151
$this->_storeManager = $storeManager;
120-
$this->settingChecker = $settingChecker ?: ObjectManager::getInstance()->get(SettingChecker::class);
152+
$this->settingChecker = $settingChecker
153+
?? ObjectManager::getInstance()->get(SettingChecker::class);
154+
$this->scopeResolverPool = $scopeResolverPool
155+
?? ObjectManager::getInstance()->get(ScopeResolverPool::class);
156+
$this->scopeTypeNormalizer = $scopeTypeNormalizer
157+
?? ObjectManager::getInstance()->get(ScopeTypeNormalizer::class);
121158
}
122159

123160
/**
@@ -505,41 +542,75 @@ public function setDataByPath($path, $value)
505542
}
506543

507544
/**
508-
* Get scope name and scopeId
545+
* Set scope data
509546
*
510-
* @todo refactor to scope resolver
511547
* @return void
512548
*/
513549
private function initScope()
514550
{
515551
if ($this->getSection() === null) {
516552
$this->setSection('');
517553
}
554+
555+
$scope = $this->retrieveScope();
556+
$this->setScope($this->scopeTypeNormalizer->normalize($scope->getScopeType()));
557+
$this->setScopeCode($scope->getCode());
558+
$this->setScopeId($scope->getId());
559+
518560
if ($this->getWebsite() === null) {
519-
$this->setWebsite('');
561+
$this->setWebsite(StoreScopeInterface::SCOPE_WEBSITES === $this->getScope() ? $scope->getId() : '');
520562
}
521563
if ($this->getStore() === null) {
522-
$this->setStore('');
564+
$this->setStore(StoreScopeInterface::SCOPE_STORES === $this->getScope() ? $scope->getId() : '');
523565
}
566+
}
524567

525-
if ($this->getStore()) {
526-
$scope = 'stores';
527-
$store = $this->_storeManager->getStore($this->getStore());
528-
$scopeId = (int)$store->getId();
529-
$scopeCode = $store->getCode();
530-
} elseif ($this->getWebsite()) {
531-
$scope = 'websites';
532-
$website = $this->_storeManager->getWebsite($this->getWebsite());
533-
$scopeId = (int)$website->getId();
534-
$scopeCode = $website->getCode();
568+
/**
569+
* Retrieve scope from initial data
570+
*
571+
* @return ScopeInterface
572+
*/
573+
private function retrieveScope(): ScopeInterface
574+
{
575+
$scopeType = $this->getScope();
576+
if (!$scopeType) {
577+
switch (true) {
578+
case $this->getStore():
579+
$scopeType = StoreScopeInterface::SCOPE_STORES;
580+
$scopeIdentifier = $this->getStore();
581+
break;
582+
case $this->getWebsite():
583+
$scopeType = StoreScopeInterface::SCOPE_WEBSITES;
584+
$scopeIdentifier = $this->getWebsite();
585+
break;
586+
default:
587+
$scopeType = ScopeInterface::SCOPE_DEFAULT;
588+
$scopeIdentifier = null;
589+
break;
590+
}
535591
} else {
536-
$scope = 'default';
537-
$scopeId = 0;
538-
$scopeCode = '';
592+
switch (true) {
593+
case $this->getScopeId() !== null:
594+
$scopeIdentifier = $this->getScopeId();
595+
break;
596+
case $this->getScopeCode() !== null:
597+
$scopeIdentifier = $this->getScopeCode();
598+
break;
599+
case $this->getStore() !== null:
600+
$scopeIdentifier = $this->getStore();
601+
break;
602+
case $this->getWebsite() !== null:
603+
$scopeIdentifier = $this->getWebsite();
604+
break;
605+
default:
606+
$scopeIdentifier = null;
607+
break;
608+
}
539609
}
540-
$this->setScope($scope);
541-
$this->setScopeId($scopeId);
542-
$this->setScopeCode($scopeCode);
610+
$scope = $this->scopeResolverPool->get($scopeType)
611+
->getScope($scopeIdentifier);
612+
613+
return $scope;
543614
}
544615

545616
/**

app/code/Magento/Config/Model/Config/Backend/Currency/AbstractCurrency.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
namespace Magento\Config\Model\Config\Backend\Currency;
1515

1616
/**
17+
* Base currency class
18+
*
1719
* @api
1820
* @since 100.0.2
1921
*/
@@ -26,18 +28,19 @@ abstract class AbstractCurrency extends \Magento\Framework\App\Config\Value
2628
*/
2729
protected function _getAllowedCurrencies()
2830
{
29-
if (!$this->isFormData() || $this->getData('groups/options/fields/allow/inherit')) {
30-
return explode(
31+
$allowValue = $this->getData('groups/options/fields/allow/value');
32+
$allowedCurrencies = $allowValue === null || $this->getData('groups/options/fields/allow/inherit')
33+
? explode(
3134
',',
3235
(string)$this->_config->getValue(
3336
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
3437
$this->getScope(),
3538
$this->getScopeId()
3639
)
37-
);
38-
}
40+
)
41+
: (array) $allowValue;
3942

40-
return (array)$this->getData('groups/options/fields/allow/value');
43+
return $allowedCurrencies;
4144
}
4245

4346
/**

0 commit comments

Comments
 (0)