-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6661 from magento-l3/PRodubovyk20210225
2.4 Bugfix Delivery L3 team
- Loading branch information
Showing
20 changed files
with
819 additions
and
29 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...alog/Test/Mftf/ActionGroup/AdminProductAttributeSetVisibleInAdvancedSearchActionGroup.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> | ||
<actionGroup name="AdminProductAttributeSetVisibleInAdvancedSearchActionGroup"> | ||
<annotations> | ||
<description>Set 'Visible in Advanced Search' value for product attribute</description> | ||
</annotations> | ||
<arguments> | ||
<argument name="isVisibleInAdvancedSearch" type="string" defaultValue="Yes"/> | ||
</arguments> | ||
|
||
<scrollToTopOfPage stepKey="scrollToTopOfPage"/> | ||
<click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="clickStorefrontPropertiesTab"/> | ||
<waitForElementVisible selector="{{AdvancedAttributePropertiesSection.VisibleInAdvancedSearch}}" stepKey="waitForVisibleInAdvancedSearchElementVisible"/> | ||
<selectOption selector="{{AdvancedAttributePropertiesSection.VisibleInAdvancedSearch}}" userInput="{{isVisibleInAdvancedSearch}}" stepKey="setVisibleInAdvancedSearchValue"/> | ||
</actionGroup> | ||
</actionGroups> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/code/Magento/CatalogSearch/Model/Search/Request/ModifierComposite.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogSearch\Model\Search\Request; | ||
|
||
/** | ||
* Search requests configuration composite modifier | ||
*/ | ||
class ModifierComposite implements ModifierInterface | ||
{ | ||
/** | ||
* @var ModifierInterface[] | ||
*/ | ||
private $modifiers; | ||
|
||
/** | ||
* @param ModifierInterface[] $modifiers | ||
*/ | ||
public function __construct( | ||
array $modifiers = [] | ||
) { | ||
foreach ($modifiers as $modifier) { | ||
if (!$modifier instanceof ModifierInterface) { | ||
throw new \InvalidArgumentException( | ||
get_class($modifier) . ' must implement ' . ModifierInterface::class | ||
); | ||
} | ||
} | ||
$this->modifiers = $modifiers; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function modify(array $requests): array | ||
{ | ||
foreach ($this->modifiers as $modifier) { | ||
$requests = $modifier->modify($requests); | ||
} | ||
return $requests; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/code/Magento/CatalogSearch/Model/Search/Request/ModifierInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogSearch\Model\Search\Request; | ||
|
||
/** | ||
* Search requests configuration modifier interface | ||
*/ | ||
interface ModifierInterface | ||
{ | ||
/** | ||
* Modifies search requests configuration | ||
* | ||
* @param array $requests | ||
* @return array | ||
*/ | ||
public function modify(array $requests): array; | ||
} |
76 changes: 76 additions & 0 deletions
76
app/code/Magento/CatalogSearch/Model/Search/Request/PartialSearchModifier.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogSearch\Model\Search\Request; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection; | ||
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory; | ||
use Magento\Eav\Model\Entity\Attribute; | ||
|
||
/** | ||
* Modifies partial search query in search requests configuration | ||
*/ | ||
class PartialSearchModifier implements ModifierInterface | ||
{ | ||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private $collectionFactory; | ||
|
||
/** | ||
* @param CollectionFactory $collectionFactory | ||
*/ | ||
public function __construct( | ||
CollectionFactory $collectionFactory | ||
) { | ||
$this->collectionFactory = $collectionFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function modify(array $requests): array | ||
{ | ||
$attributes = $this->getSearchableAttributes(); | ||
foreach ($requests as $code => $request) { | ||
$matches = $request['queries']['partial_search']['match'] ?? []; | ||
if ($matches) { | ||
foreach ($matches as $index => $match) { | ||
$field = $match['field'] ?? null; | ||
if ($field && $field !== '*' && !isset($attributes[$field])) { | ||
unset($matches[$index]); | ||
} | ||
} | ||
$requests[$code]['queries']['partial_search']['match'] = array_values($matches); | ||
} | ||
} | ||
return $requests; | ||
} | ||
|
||
/** | ||
* Retrieve searchable attributes | ||
* | ||
* @return Attribute[] | ||
*/ | ||
private function getSearchableAttributes(): array | ||
{ | ||
$attributes = []; | ||
/** @var Collection $collection */ | ||
$collection = $this->collectionFactory->create(); | ||
$collection->addFieldToFilter( | ||
['is_searchable', 'is_visible_in_advanced_search', 'is_filterable', 'is_filterable_in_search'], | ||
[1, 1, [1, 2], 1] | ||
); | ||
|
||
/** @var Attribute $attribute */ | ||
foreach ($collection->getItems() as $attribute) { | ||
$attributes[$attribute->getAttributeCode()] = $attribute; | ||
} | ||
|
||
return $attributes; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/code/Magento/CatalogSearch/Model/Search/Request/SearchModifier.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogSearch\Model\Search\Request; | ||
|
||
use Magento\CatalogSearch\Model\Search\RequestGenerator; | ||
|
||
/** | ||
* Modifies search requests configuration | ||
*/ | ||
class SearchModifier implements ModifierInterface | ||
{ | ||
/** | ||
* @var RequestGenerator | ||
*/ | ||
private $requestGenerator; | ||
|
||
/** | ||
* @param RequestGenerator $requestGenerator | ||
*/ | ||
public function __construct( | ||
RequestGenerator $requestGenerator | ||
) { | ||
$this->requestGenerator = $requestGenerator; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function modify(array $requests): array | ||
{ | ||
$requests = array_merge_recursive($requests, $this->requestGenerator->generate()); | ||
return $requests; | ||
} | ||
} |
Oops, something went wrong.