Skip to content

Commit

Permalink
Merge pull request #6661 from magento-l3/PRodubovyk20210225
Browse files Browse the repository at this point in the history
2.4 Bugfix Delivery L3 team
  • Loading branch information
gabrieldagama authored Mar 6, 2021
2 parents 1b4ecb5 + c366b0d commit d1a2753
Show file tree
Hide file tree
Showing 20 changed files with 819 additions and 29 deletions.
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>
19 changes: 11 additions & 8 deletions app/code/Magento/CatalogSearch/Model/Search/ReaderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,44 @@
*/
namespace Magento\CatalogSearch\Model\Search;

use Magento\CatalogSearch\Model\Search\Request\ModifierInterface;
use Magento\Framework\Config\ReaderInterface;

/**
* @deprecated 101.0.0
* @see \Magento\ElasticSearch
*/
class ReaderPlugin
{
/**
* @var \Magento\CatalogSearch\Model\Search\RequestGenerator
* @var ModifierInterface
*/
private $requestGenerator;
private $requestModifier;

/**
* @param \Magento\CatalogSearch\Model\Search\RequestGenerator $requestGenerator
* @param ModifierInterface $requestModifier
*/
public function __construct(
\Magento\CatalogSearch\Model\Search\RequestGenerator $requestGenerator
ModifierInterface $requestModifier
) {
$this->requestGenerator = $requestGenerator;
$this->requestModifier = $requestModifier;
}

/**
* Merge reader's value with generated
*
* @param \Magento\Framework\Config\ReaderInterface $subject
* @param ReaderInterface $subject
* @param array $result
* @param string|null $scope
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterRead(
\Magento\Framework\Config\ReaderInterface $subject,
ReaderInterface $subject,
array $result,
$scope = null
) {
$result = array_merge_recursive($result, $this->requestGenerator->generate());
$result = $this->requestModifier->modify($result);
return $result;
}
}
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;
}
}
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;
}
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;
}
}
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;
}
}
Loading

0 comments on commit d1a2753

Please sign in to comment.