Skip to content

Commit d1a2753

Browse files
Merge pull request #6661 from magento-l3/PRodubovyk20210225
2.4 Bugfix Delivery L3 team
2 parents 1b4ecb5 + c366b0d commit d1a2753

File tree

20 files changed

+819
-29
lines changed

20 files changed

+819
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminProductAttributeSetVisibleInAdvancedSearchActionGroup">
11+
<annotations>
12+
<description>Set 'Visible in Advanced Search' value for product attribute</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="isVisibleInAdvancedSearch" type="string" defaultValue="Yes"/>
16+
</arguments>
17+
18+
<scrollToTopOfPage stepKey="scrollToTopOfPage"/>
19+
<click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="clickStorefrontPropertiesTab"/>
20+
<waitForElementVisible selector="{{AdvancedAttributePropertiesSection.VisibleInAdvancedSearch}}" stepKey="waitForVisibleInAdvancedSearchElementVisible"/>
21+
<selectOption selector="{{AdvancedAttributePropertiesSection.VisibleInAdvancedSearch}}" userInput="{{isVisibleInAdvancedSearch}}" stepKey="setVisibleInAdvancedSearchValue"/>
22+
</actionGroup>
23+
</actionGroups>

app/code/Magento/CatalogSearch/Model/Search/ReaderPlugin.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,44 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Search;
77

8+
use Magento\CatalogSearch\Model\Search\Request\ModifierInterface;
9+
use Magento\Framework\Config\ReaderInterface;
10+
811
/**
912
* @deprecated 101.0.0
1013
* @see \Magento\ElasticSearch
1114
*/
1215
class ReaderPlugin
1316
{
1417
/**
15-
* @var \Magento\CatalogSearch\Model\Search\RequestGenerator
18+
* @var ModifierInterface
1619
*/
17-
private $requestGenerator;
20+
private $requestModifier;
1821

1922
/**
20-
* @param \Magento\CatalogSearch\Model\Search\RequestGenerator $requestGenerator
23+
* @param ModifierInterface $requestModifier
2124
*/
2225
public function __construct(
23-
\Magento\CatalogSearch\Model\Search\RequestGenerator $requestGenerator
26+
ModifierInterface $requestModifier
2427
) {
25-
$this->requestGenerator = $requestGenerator;
28+
$this->requestModifier = $requestModifier;
2629
}
2730

2831
/**
2932
* Merge reader's value with generated
3033
*
31-
* @param \Magento\Framework\Config\ReaderInterface $subject
34+
* @param ReaderInterface $subject
3235
* @param array $result
3336
* @param string|null $scope
3437
* @return array
3538
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3639
*/
3740
public function afterRead(
38-
\Magento\Framework\Config\ReaderInterface $subject,
41+
ReaderInterface $subject,
3942
array $result,
4043
$scope = null
4144
) {
42-
$result = array_merge_recursive($result, $this->requestGenerator->generate());
45+
$result = $this->requestModifier->modify($result);
4346
return $result;
4447
}
4548
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\CatalogSearch\Model\Search\Request;
9+
10+
/**
11+
* Search requests configuration composite modifier
12+
*/
13+
class ModifierComposite implements ModifierInterface
14+
{
15+
/**
16+
* @var ModifierInterface[]
17+
*/
18+
private $modifiers;
19+
20+
/**
21+
* @param ModifierInterface[] $modifiers
22+
*/
23+
public function __construct(
24+
array $modifiers = []
25+
) {
26+
foreach ($modifiers as $modifier) {
27+
if (!$modifier instanceof ModifierInterface) {
28+
throw new \InvalidArgumentException(
29+
get_class($modifier) . ' must implement ' . ModifierInterface::class
30+
);
31+
}
32+
}
33+
$this->modifiers = $modifiers;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function modify(array $requests): array
40+
{
41+
foreach ($this->modifiers as $modifier) {
42+
$requests = $modifier->modify($requests);
43+
}
44+
return $requests;
45+
}
46+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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\CatalogSearch\Model\Search\Request;
9+
10+
/**
11+
* Search requests configuration modifier interface
12+
*/
13+
interface ModifierInterface
14+
{
15+
/**
16+
* Modifies search requests configuration
17+
*
18+
* @param array $requests
19+
* @return array
20+
*/
21+
public function modify(array $requests): array;
22+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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\CatalogSearch\Model\Search\Request;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection;
11+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
12+
use Magento\Eav\Model\Entity\Attribute;
13+
14+
/**
15+
* Modifies partial search query in search requests configuration
16+
*/
17+
class PartialSearchModifier implements ModifierInterface
18+
{
19+
/**
20+
* @var CollectionFactory
21+
*/
22+
private $collectionFactory;
23+
24+
/**
25+
* @param CollectionFactory $collectionFactory
26+
*/
27+
public function __construct(
28+
CollectionFactory $collectionFactory
29+
) {
30+
$this->collectionFactory = $collectionFactory;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function modify(array $requests): array
37+
{
38+
$attributes = $this->getSearchableAttributes();
39+
foreach ($requests as $code => $request) {
40+
$matches = $request['queries']['partial_search']['match'] ?? [];
41+
if ($matches) {
42+
foreach ($matches as $index => $match) {
43+
$field = $match['field'] ?? null;
44+
if ($field && $field !== '*' && !isset($attributes[$field])) {
45+
unset($matches[$index]);
46+
}
47+
}
48+
$requests[$code]['queries']['partial_search']['match'] = array_values($matches);
49+
}
50+
}
51+
return $requests;
52+
}
53+
54+
/**
55+
* Retrieve searchable attributes
56+
*
57+
* @return Attribute[]
58+
*/
59+
private function getSearchableAttributes(): array
60+
{
61+
$attributes = [];
62+
/** @var Collection $collection */
63+
$collection = $this->collectionFactory->create();
64+
$collection->addFieldToFilter(
65+
['is_searchable', 'is_visible_in_advanced_search', 'is_filterable', 'is_filterable_in_search'],
66+
[1, 1, [1, 2], 1]
67+
);
68+
69+
/** @var Attribute $attribute */
70+
foreach ($collection->getItems() as $attribute) {
71+
$attributes[$attribute->getAttributeCode()] = $attribute;
72+
}
73+
74+
return $attributes;
75+
}
76+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\CatalogSearch\Model\Search\Request;
9+
10+
use Magento\CatalogSearch\Model\Search\RequestGenerator;
11+
12+
/**
13+
* Modifies search requests configuration
14+
*/
15+
class SearchModifier implements ModifierInterface
16+
{
17+
/**
18+
* @var RequestGenerator
19+
*/
20+
private $requestGenerator;
21+
22+
/**
23+
* @param RequestGenerator $requestGenerator
24+
*/
25+
public function __construct(
26+
RequestGenerator $requestGenerator
27+
) {
28+
$this->requestGenerator = $requestGenerator;
29+
}
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
public function modify(array $requests): array
35+
{
36+
$requests = array_merge_recursive($requests, $this->requestGenerator->generate());
37+
return $requests;
38+
}
39+
}

0 commit comments

Comments
 (0)