Skip to content

Commit 07ca5f5

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into MCP-218
2 parents f5db9f9 + d1a2753 commit 07ca5f5

File tree

26 files changed

+1378
-53
lines changed

26 files changed

+1378
-53
lines changed

app/code/Magento/Bundle/Model/Product/BundleOptionDataProvider.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Bundle\Model\Option;
1212
use Magento\Catalog\Model\Product;
1313
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
14+
use Magento\Framework\GraphQl\Query\Uid;
1415
use Magento\Framework\Pricing\Helper\Data;
1516
use Magento\Framework\Serialize\SerializerInterface;
1617

@@ -19,6 +20,11 @@
1920
*/
2021
class BundleOptionDataProvider
2122
{
23+
/**
24+
* Option type name
25+
*/
26+
private const OPTION_TYPE = 'bundle';
27+
2228
/**
2329
* @var Data
2430
*/
@@ -34,19 +40,27 @@ class BundleOptionDataProvider
3440
*/
3541
private $configuration;
3642

43+
/**
44+
* @var Uid
45+
*/
46+
private $uidEncoder;
47+
3748
/**
3849
* @param Data $pricingHelper
3950
* @param SerializerInterface $serializer
4051
* @param Configuration $configuration
52+
* @param Uid $uidEncoder
4153
*/
4254
public function __construct(
4355
Data $pricingHelper,
4456
SerializerInterface $serializer,
45-
Configuration $configuration
57+
Configuration $configuration,
58+
Uid $uidEncoder
4659
) {
4760
$this->pricingHelper = $pricingHelper;
4861
$this->serializer = $serializer;
4962
$this->configuration = $configuration;
63+
$this->uidEncoder = $uidEncoder;
5064
}
5165

5266
/**
@@ -100,8 +114,15 @@ private function buildBundleOptions(array $bundleOptions, ItemInterface $item):
100114
continue;
101115
}
102116

117+
$optionDetails = [
118+
self::OPTION_TYPE,
119+
$bundleOption->getOptionId()
120+
];
121+
$uidString = implode('/', $optionDetails);
122+
103123
$options[] = [
104124
'id' => $bundleOption->getId(),
125+
'uid' => $this->uidEncoder->encode($uidString),
105126
'label' => $bundleOption->getTitle(),
106127
'type' => $bundleOption->getType(),
107128
'values' => $this->buildBundleOptionValues($bundleOption->getSelections(), $item),
@@ -130,10 +151,19 @@ private function buildBundleOptionValues(array $selections, ItemInterface $item)
130151
continue;
131152
}
132153

154+
$optionValueDetails = [
155+
self::OPTION_TYPE,
156+
$selection->getOptionId(),
157+
$selection->getSelectionId(),
158+
(int) $selection->getSelectionQty()
159+
];
160+
$uidString = implode('/', $optionValueDetails);
161+
133162
$selectionPrice = $this->configuration->getSelectionFinalPrice($item, $selection);
134163
$values[] = [
135-
'label' => $selection->getName(),
136164
'id' => $selection->getSelectionId(),
165+
'uid' => $this->uidEncoder->encode($uidString),
166+
'label' => $selection->getName(),
137167
'quantity' => $qty,
138168
'price' => $this->pricingHelper->currency($selectionPrice, false, false),
139169
];
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)