Skip to content

Commit ab51e5a

Browse files
committed
Merge remote-tracking branch 'mainline/2.3-develop' into DEVOPS-2174
2 parents 4fd8aaa + 7deeca2 commit ab51e5a

File tree

119 files changed

+4242
-575
lines changed

Some content is hidden

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

119 files changed

+4242
-575
lines changed

app/code/Magento/Catalog/Console/Command/ImagesResizeCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ protected function execute(
6969
$productIds = $productCollection->getAllIds();
7070
if (!count($productIds)) {
7171
$output->writeln("<info>No product images to resize</info>");
72-
// we must have an exit code higher than zero to indicate something was wrong
7372
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
7473
}
7574

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Model\Config\Source;
10+
11+
use Magento\Catalog\Model\Product\Attribute\Source\Layout;
12+
13+
/**
14+
* Returns layout list for Web>Default Layouts>Default Product Layout/Default Category Layout
15+
*/
16+
class LayoutList implements \Magento\Framework\Option\ArrayInterface
17+
{
18+
/**
19+
* @var array
20+
*/
21+
private $options;
22+
23+
/**
24+
* @var \Magento\Catalog\Model\Product\Attribute\Source\Layout
25+
*/
26+
private $layoutSource;
27+
28+
/**
29+
* @param Layout $layoutSource
30+
*/
31+
public function __construct(
32+
Layout $layoutSource
33+
) {
34+
$this->layoutSource = $layoutSource;
35+
}
36+
37+
/**
38+
* To option array
39+
*
40+
* @return array
41+
*/
42+
public function toOptionArray()
43+
{
44+
if (!$this->options) {
45+
$this->options = $this->layoutSource->getAllOptions();
46+
}
47+
return $this->options;
48+
}
49+
}

app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getDefaultStoreId()
140140
*
141141
* @param string $table
142142
* @param array|int $attributeIds
143-
* @return \Magento\Eav\Model\Entity\Collection\AbstractCollection
143+
* @return \Magento\Framework\DB\Select
144144
*/
145145
protected function _getLoadAttributesSelect($table, $attributeIds = [])
146146
{

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Magento\Ui\DataProvider\Mapper\FormElement as FormElementMapper;
3333
use Magento\Ui\DataProvider\Mapper\MetaProperties as MetaPropertiesMapper;
3434
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav\CompositeConfigProcessor;
35+
use Magento\Framework\App\Config\ScopeConfigInterface;
3536

3637
/**
3738
* Class Eav
@@ -194,6 +195,12 @@ class Eav extends AbstractModifier
194195
private $wysiwygConfigProcessor;
195196

196197
/**
198+
* @var ScopeConfigInterface
199+
*/
200+
private $scopeConfig;
201+
202+
/**
203+
* Eav constructor.
197204
* @param LocatorInterface $locator
198205
* @param CatalogEavValidationRules $catalogEavValidationRules
199206
* @param Config $eavConfig
@@ -214,6 +221,7 @@ class Eav extends AbstractModifier
214221
* @param array $attributesToDisable
215222
* @param array $attributesToEliminate
216223
* @param CompositeConfigProcessor|null $wysiwygConfigProcessor
224+
* @param ScopeConfigInterface|null $scopeConfig
217225
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
218226
*/
219227
public function __construct(
@@ -236,7 +244,8 @@ public function __construct(
236244
DataPersistorInterface $dataPersistor,
237245
$attributesToDisable = [],
238246
$attributesToEliminate = [],
239-
CompositeConfigProcessor $wysiwygConfigProcessor = null
247+
CompositeConfigProcessor $wysiwygConfigProcessor = null,
248+
ScopeConfigInterface $scopeConfig = null
240249
) {
241250
$this->locator = $locator;
242251
$this->catalogEavValidationRules = $catalogEavValidationRules;
@@ -259,6 +268,8 @@ public function __construct(
259268
$this->attributesToEliminate = $attributesToEliminate;
260269
$this->wysiwygConfigProcessor = $wysiwygConfigProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
261270
->get(CompositeConfigProcessor::class);
271+
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()
272+
->get(ScopeConfigInterface::class);
262273
}
263274

264275
/**
@@ -582,14 +593,13 @@ private function isProductExists()
582593
public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupCode, $sortOrder)
583594
{
584595
$configPath = ltrim(static::META_CONFIG_PATH, ArrayManager::DEFAULT_PATH_DELIMITER);
585-
586596
$meta = $this->arrayManager->set($configPath, [], [
587597
'dataType' => $attribute->getFrontendInput(),
588598
'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()),
589599
'visible' => $attribute->getIsVisible(),
590600
'required' => $attribute->getIsRequired(),
591601
'notice' => $attribute->getNote() === null ? null : __($attribute->getNote()),
592-
'default' => (!$this->isProductExists()) ? $attribute->getDefaultValue() : null,
602+
'default' => (!$this->isProductExists()) ? $this->getAttributeDefaultValue($attribute) : null,
593603
'label' => __($attribute->getDefaultFrontendLabel()),
594604
'code' => $attribute->getAttributeCode(),
595605
'source' => $groupCode,
@@ -655,6 +665,24 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
655665
return $meta;
656666
}
657667

668+
/**
669+
* Returns attribute default value, based on db setting or setting in the system configuration
670+
* @param ProductAttributeInterface $attribute
671+
* @return null|string
672+
*/
673+
private function getAttributeDefaultValue(ProductAttributeInterface $attribute)
674+
{
675+
if ($attribute->getAttributeCode() === 'page_layout') {
676+
$defaultValue = $this->scopeConfig->getValue(
677+
'web/default_layouts/default_product_layout',
678+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
679+
$this->storeManager->getStore()
680+
);
681+
$attribute->setDefaultValue($defaultValue);
682+
}
683+
return $attribute->getDefaultValue();
684+
}
685+
658686
/**
659687
* @param ProductAttributeInterface $attribute
660688
* @param array $meta

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,9 @@
200200
</argument>
201201
</arguments>
202202
</type>
203+
<virtualType name="Magento\Catalog\Ui\Component\Form\Field\Category\PageLayout" type="Magento\Ui\Component\Form\Field\DefaultValue">
204+
<arguments>
205+
<argument name="path" xsi:type="string">web/default_layouts/default_category_layout</argument>
206+
</arguments>
207+
</virtualType>
203208
</config>

app/code/Magento/Catalog/etc/adminhtml/system.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,18 @@
186186
</field>
187187
</group>
188188
</section>
189+
<section id="web">
190+
<group id="default_layouts" translate="label" type="text" sortOrder="35" showInDefault="1">
191+
<label>Default Layouts</label>
192+
<field id="default_product_layout" translate="label" type="select" sortOrder="10" showInDefault="1">
193+
<label>Default Product Layout</label>
194+
<source_model>Magento\Catalog\Model\Config\Source\LayoutList</source_model>
195+
</field>
196+
<field id="default_category_layout" translate="label" type="select" sortOrder="20" showInDefault="1">
197+
<label>Default Category Layout</label>
198+
<source_model>Magento\Catalog\Model\Config\Source\LayoutList</source_model>
199+
</field>
200+
</group>
201+
</section>
189202
</system>
190203
</config>

app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@
463463
</imports>
464464
</settings>
465465
</field>
466-
<field name="page_layout" sortOrder="190" formElement="select">
466+
<field name="page_layout" sortOrder="190" formElement="select" class="Magento\Catalog\Ui\Component\Form\Field\Category\PageLayout">
467467
<settings>
468468
<dataType>string</dataType>
469469
<label translate="true">Layout</label>

app/code/Magento/CatalogImportExport/Model/Indexer/Product/Flat/Plugin/Import.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin;
77

8+
use Magento\Catalog\Model\Indexer\Product\Flat\State as FlatState;
9+
810
class Import
911
{
12+
/**
13+
* @var \Magento\Catalog\Model\Indexer\Product\Flat\State
14+
*/
15+
private $flatState;
16+
1017
/**
1118
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor
1219
*/
1320
protected $_productFlatIndexerProcessor;
1421

1522
/**
1623
* @param \Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor
24+
* @param \Magento\Catalog\Model\Indexer\Product\Flat\State $flatState
1725
*/
18-
public function __construct(\Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor)
19-
{
26+
public function __construct(
27+
\Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor,
28+
FlatState $flatState
29+
) {
2030
$this->_productFlatIndexerProcessor = $productFlatIndexerProcessor;
31+
$this->flatState = $flatState;
2132
}
2233

2334
/**
@@ -31,7 +42,10 @@ public function __construct(\Magento\Catalog\Model\Indexer\Product\Flat\Processo
3142
*/
3243
public function afterImportSource(\Magento\ImportExport\Model\Import $subject, $import)
3344
{
34-
$this->_productFlatIndexerProcessor->markIndexerAsInvalid();
45+
if ($this->flatState->isFlatEnabled() && !$this->_productFlatIndexerProcessor->isIndexerScheduled()) {
46+
$this->_productFlatIndexerProcessor->markIndexerAsInvalid();
47+
}
48+
3549
return $import;
3650
}
3751
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Indexer/Product/Flat/Plugin/ImportTest.php

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,79 @@
55
*/
66
namespace Magento\CatalogImportExport\Test\Unit\Model\Indexer\Product\Flat\Plugin;
77

8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
810
class ImportTest extends \PHPUnit\Framework\TestCase
911
{
10-
public function testAfterImportSource()
12+
/**
13+
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor|\PHPUnit_Framework_MockObject_MockObject
14+
*/
15+
private $processorMock;
16+
17+
/**
18+
* @var \Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import
19+
*/
20+
private $model;
21+
22+
/**
23+
* @var \Magento\Catalog\Model\Indexer\Product\Flat\State|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $flatStateMock;
26+
27+
/**
28+
* @var \Magento\ImportExport\Model\Import|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $subjectMock;
31+
32+
protected function setUp()
1133
{
12-
/**
13-
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor|
14-
* \PHPUnit_Framework_MockObject_MockObject $processorMock
15-
*/
16-
$processorMock = $this->createPartialMock(
17-
\Magento\Catalog\Model\Indexer\Product\Flat\Processor::class,
18-
['markIndexerAsInvalid']
34+
$this->processorMock = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Product\Flat\Processor::class)
35+
->disableOriginalConstructor()
36+
->setMethods(['markIndexerAsInvalid', 'isIndexerScheduled'])
37+
->getMock();
38+
39+
$this->flatStateMock = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Product\Flat\State::class)
40+
->disableOriginalConstructor()
41+
->setMethods(['isFlatEnabled'])
42+
->getMock();
43+
44+
$this->subjectMock = $this->getMockBuilder(\Magento\ImportExport\Model\Import::class)
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$this->model = (new ObjectManager($this))->getObject(
49+
\Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import::class,
50+
[
51+
'productFlatIndexerProcessor' => $this->processorMock,
52+
'flatState' => $this->flatStateMock
53+
]
1954
);
55+
}
2056

21-
$subjectMock = $this->createMock(\Magento\ImportExport\Model\Import::class);
22-
$processorMock->expects($this->once())->method('markIndexerAsInvalid');
57+
public function testAfterImportSourceWithFlatEnabledAndIndexerScheduledDisabled()
58+
{
59+
$this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true);
60+
$this->processorMock->expects($this->once())->method('isIndexerScheduled')->willReturn(false);
61+
$this->processorMock->expects($this->once())->method('markIndexerAsInvalid');
62+
$someData = [1, 2, 3];
63+
$this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData));
64+
}
2365

66+
public function testAfterImportSourceWithFlatDisabledAndIndexerScheduledDisabled()
67+
{
68+
$this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(false);
69+
$this->processorMock->expects($this->never())->method('isIndexerScheduled')->willReturn(false);
70+
$this->processorMock->expects($this->never())->method('markIndexerAsInvalid');
2471
$someData = [1, 2, 3];
72+
$this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData));
73+
}
2574

26-
$model = new \Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import($processorMock);
27-
$this->assertEquals($someData, $model->afterImportSource($subjectMock, $someData));
75+
public function testAfterImportSourceWithFlatEnabledAndIndexerScheduledEnabled()
76+
{
77+
$this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true);
78+
$this->processorMock->expects($this->once())->method('isIndexerScheduled')->willReturn(true);
79+
$this->processorMock->expects($this->never())->method('markIndexerAsInvalid');
80+
$someData = [1, 2, 3];
81+
$this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData));
2882
}
2983
}

app/code/Magento/Cms/Block/Adminhtml/Block/Edit/ResetButton.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)