Skip to content

Commit 654f81c

Browse files
committed
Merge remote-tracking branch 'magento/2.3-develop' into PR-2.3-develop
2 parents 21ce591 + c0a3931 commit 654f81c

File tree

92 files changed

+2706
-326
lines changed

Some content is hidden

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

92 files changed

+2706
-326
lines changed

app/code/Magento/Backend/App/Request/BackendValidator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ private function createException(
146146
$exception = new InvalidRequestException($response);
147147
} else {
148148
//For regular requests.
149+
$startPageUrl = $this->backendUrl->getStartupPageUrl();
149150
$response = $this->redirectFactory->create()
150-
->setUrl($this->backendUrl->getStartupPageUrl());
151+
->setUrl($this->backendUrl->getUrl($startPageUrl));
151152
$exception = new InvalidRequestException(
152153
$response,
153154
[

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ private function getDefaultListingMode()
178178
}
179179

180180
/**
181-
* Need use as _prepareLayout - but problem in declaring collection from
182-
* another block (was problem with search result)
181+
* Need use as _prepareLayout - but problem in declaring collection from another block.
182+
* (was problem with search result)
183+
*
183184
* @return $this
184185
*/
185186
protected function _beforeToHtml()
@@ -188,7 +189,9 @@ protected function _beforeToHtml()
188189

189190
$this->addToolbarBlock($collection);
190191

191-
$collection->load();
192+
if (!$collection->isLoaded()) {
193+
$collection->load();
194+
}
192195

193196
return parent::_beforeToHtml();
194197
}
@@ -262,6 +265,8 @@ public function getToolbarHtml()
262265
}
263266

264267
/**
268+
* Set collection.
269+
*
265270
* @param AbstractCollection $collection
266271
* @return $this
267272
*/
@@ -272,7 +277,9 @@ public function setCollection($collection)
272277
}
273278

274279
/**
275-
* @param array|string|integer| Element $code
280+
* Add attribute.
281+
*
282+
* @param array|string|integer|Element $code
276283
* @return $this
277284
*/
278285
public function addAttribute($code)
@@ -282,6 +289,8 @@ public function addAttribute($code)
282289
}
283290

284291
/**
292+
* Get price block template.
293+
*
285294
* @return mixed
286295
*/
287296
public function getPriceBlockTemplate()
@@ -371,6 +380,8 @@ public function getAddToCartPostParams(Product $product)
371380
}
372381

373382
/**
383+
* Get product price.
384+
*
374385
* @param Product $product
375386
* @return string
376387
*/
@@ -396,8 +407,8 @@ public function getProductPrice(Product $product)
396407
}
397408

398409
/**
399-
* Specifies that price rendering should be done for the list of products
400-
* i.e. rendering happens in the scope of product list, but not single product
410+
* Specifies that price rendering should be done for the list of products.
411+
* (rendering happens in the scope of product list, but not single product)
401412
*
402413
* @return Render
403414
*/
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Ui\Component;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Catalog\Ui\Component\ColumnFactory;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
14+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
15+
use Magento\Framework\View\Element\UiComponentFactory;
16+
use Magento\Ui\Component\Listing\Columns\ColumnInterface;
17+
use Magento\Ui\Component\Filters\FilterModifier;
18+
19+
/**
20+
* ColumnFactory test.
21+
*/
22+
class ColumnFactoryTest extends TestCase
23+
{
24+
/**
25+
* @var ColumnFactory
26+
*/
27+
private $columnFactory;
28+
29+
/**
30+
* @var ObjectManager
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var ProductAttributeInterface|\PHPUnit\Framework\MockObject\MockObject
36+
*/
37+
private $attribute;
38+
39+
/**
40+
* @var ContextInterface|\PHPUnit\Framework\MockObject\MockObject
41+
*/
42+
private $context;
43+
44+
/**
45+
* @var UiComponentFactory|\PHPUnit\Framework\MockObject\MockObject
46+
*/
47+
private $uiComponentFactory;
48+
49+
/**
50+
* @var ColumnInterface|\PHPUnit\Framework\MockObject\MockObject
51+
*/
52+
private $column;
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
protected function setUp(): void
58+
{
59+
$this->objectManager = new ObjectManager($this);
60+
61+
$this->attribute = $this->getMockBuilder(ProductAttributeInterface::class)
62+
->setMethods(['usesSource'])
63+
->getMockForAbstractClass();
64+
$this->context = $this->createMock(ContextInterface::class);
65+
$this->uiComponentFactory = $this->createMock(UiComponentFactory::class);
66+
$this->column = $this->getMockForAbstractClass(ColumnInterface::class);
67+
$this->uiComponentFactory->method('create')
68+
->willReturn($this->column);
69+
70+
$this->columnFactory = $this->objectManager->getObject(ColumnFactory::class, [
71+
'componentFactory' => $this->uiComponentFactory
72+
]);
73+
}
74+
75+
/**
76+
* Tests the create method will return correct object.
77+
*
78+
* @return void
79+
*/
80+
public function testCreatedObject(): void
81+
{
82+
$this->context->method('getRequestParam')
83+
->with(FilterModifier::FILTER_MODIFIER, [])
84+
->willReturn([]);
85+
86+
$object = $this->columnFactory->create($this->attribute, $this->context);
87+
$this->assertEquals(
88+
$this->column,
89+
$object,
90+
'Object must be the same which the ui component factory creates.'
91+
);
92+
}
93+
94+
/**
95+
* Tests create method with not filterable in grid attribute.
96+
*
97+
* @param array $filterModifiers
98+
* @param null|string $filter
99+
*
100+
* @return void
101+
* @dataProvider filterModifiersProvider
102+
*/
103+
public function testCreateWithNotFilterableInGridAttribute(array $filterModifiers, ?string $filter): void
104+
{
105+
$componentFactoryArgument = [
106+
'data' => [
107+
'config' => [
108+
'label' => __(null),
109+
'dataType' => 'text',
110+
'add_field' => true,
111+
'visible' => null,
112+
'filter' => $filter,
113+
'component' => 'Magento_Ui/js/grid/columns/column',
114+
],
115+
],
116+
'context' => $this->context,
117+
];
118+
119+
$this->context->method('getRequestParam')
120+
->with(FilterModifier::FILTER_MODIFIER, [])
121+
->willReturn($filterModifiers);
122+
$this->attribute->method('getIsFilterableInGrid')
123+
->willReturn(false);
124+
$this->attribute->method('getAttributeCode')
125+
->willReturn('color');
126+
127+
$this->uiComponentFactory->expects($this->once())
128+
->method('create')
129+
->with($this->anything(), $this->anything(), $componentFactoryArgument);
130+
131+
$this->columnFactory->create($this->attribute, $this->context);
132+
}
133+
134+
/**
135+
* Filter modifiers data provider.
136+
*
137+
* @return array
138+
*/
139+
public function filterModifiersProvider(): array
140+
{
141+
return [
142+
'without' => [
143+
'filter_modifiers' => [],
144+
'filter' => null,
145+
],
146+
'with' => [
147+
'filter_modifiers' => [
148+
'color' => [
149+
'condition_type' => 'notnull',
150+
],
151+
],
152+
'filter' => 'text',
153+
],
154+
];
155+
}
156+
}

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Ui\Component;
77

8+
use Magento\Ui\Component\Filters\FilterModifier;
9+
810
/**
911
* Column Factory
1012
*
@@ -60,13 +62,15 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
6062
*/
6163
public function create($attribute, $context, array $config = [])
6264
{
65+
$filterModifiers = $context->getRequestParam(FilterModifier::FILTER_MODIFIER, []);
66+
6367
$columnName = $attribute->getAttributeCode();
6468
$config = array_merge([
6569
'label' => __($attribute->getDefaultFrontendLabel()),
6670
'dataType' => $this->getDataType($attribute),
6771
'add_field' => true,
6872
'visible' => $attribute->getIsVisibleInGrid(),
69-
'filter' => ($attribute->getIsFilterableInGrid())
73+
'filter' => ($attribute->getIsFilterableInGrid() || array_key_exists($columnName, $filterModifiers))
7074
? $this->getFilterType($attribute->getFrontendInput())
7175
: null,
7276
], $config);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ private function addAdvancedPriceLink()
389389
'componentType' => Container::NAME,
390390
'component' => 'Magento_Ui/js/form/components/button',
391391
'template' => 'ui/form/components/button/container',
392+
'imports' => [
393+
'childError' => $this->scopeName . '.advanced_pricing_modal.advanced-pricing:error',
394+
],
392395
'actions' => [
393396
[
394397
'targetName' => $this->scopeName . '.advanced_pricing_modal',

app/code/Magento/CatalogInventory/Model/AddStockStatusToCollection.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\CatalogInventory\Model;
88

99
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Framework\Search\EngineResolverInterface;
11+
use Magento\Search\Model\EngineResolver;
1012

1113
/**
1214
* Catalog inventory module plugin
@@ -17,26 +19,37 @@ class AddStockStatusToCollection
1719
* @var \Magento\CatalogInventory\Helper\Stock
1820
*/
1921
protected $stockHelper;
20-
22+
23+
/**
24+
* @var EngineResolverInterface
25+
*/
26+
private $engineResolver;
27+
2128
/**
22-
* @param \Magento\CatalogInventory\Model\Configuration $configuration
2329
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
30+
* @param EngineResolverInterface $engineResolver
2431
*/
2532
public function __construct(
26-
\Magento\CatalogInventory\Helper\Stock $stockHelper
33+
\Magento\CatalogInventory\Helper\Stock $stockHelper,
34+
EngineResolverInterface $engineResolver
2735
) {
2836
$this->stockHelper = $stockHelper;
37+
$this->engineResolver = $engineResolver;
2938
}
3039

3140
/**
41+
* Add stock filter to collection.
42+
*
3243
* @param Collection $productCollection
3344
* @param bool $printQuery
3445
* @param bool $logQuery
3546
* @return array
3647
*/
3748
public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false)
3849
{
39-
$this->stockHelper->addIsInStockFilterToCollection($productCollection);
50+
if ($this->engineResolver->getCurrentSearchEngine() === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE) {
51+
$this->stockHelper->addIsInStockFilterToCollection($productCollection);
52+
}
4053
return [$printQuery, $logQuery];
4154
}
4255
}

app/code/Magento/CatalogInventory/Model/Plugin/Layer.php

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

9+
use Magento\Framework\Search\EngineResolverInterface;
10+
use Magento\Search\Model\EngineResolver;
11+
12+
/**
13+
* Catalog inventory plugin for layer.
14+
*/
815
class Layer
916
{
1017
/**
@@ -21,16 +28,24 @@ class Layer
2128
*/
2229
protected $scopeConfig;
2330

31+
/**
32+
* @var EngineResolverInterface
33+
*/
34+
private $engineResolver;
35+
2436
/**
2537
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
2638
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
39+
* @param EngineResolverInterface $engineResolver
2740
*/
2841
public function __construct(
2942
\Magento\CatalogInventory\Helper\Stock $stockHelper,
30-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
43+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
44+
EngineResolverInterface $engineResolver
3145
) {
3246
$this->stockHelper = $stockHelper;
3347
$this->scopeConfig = $scopeConfig;
48+
$this->engineResolver = $engineResolver;
3449
}
3550

3651
/**
@@ -46,12 +61,22 @@ public function beforePrepareProductCollection(
4661
\Magento\Catalog\Model\Layer $subject,
4762
\Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection
4863
) {
49-
if ($this->_isEnabledShowOutOfStock()) {
64+
if (!$this->isCurrentEngineMysql() || $this->_isEnabledShowOutOfStock()) {
5065
return;
5166
}
5267
$this->stockHelper->addIsInStockFilterToCollection($collection);
5368
}
5469

70+
/**
71+
* Check if current engine is MYSQL.
72+
*
73+
* @return bool
74+
*/
75+
private function isCurrentEngineMysql()
76+
{
77+
return $this->engineResolver->getCurrentSearchEngine() === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE;
78+
}
79+
5580
/**
5681
* Get config value for 'display out of stock' option
5782
*

0 commit comments

Comments
 (0)