Skip to content

Commit 9f44ea8

Browse files
Merge remote-tracking branch 'origin/MC-35491' into 2.4-develop-pr33
2 parents 0fd2b96 + 9b1284e commit 9f44ea8

File tree

4 files changed

+79
-8
lines changed

4 files changed

+79
-8
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\Search\ViewModel;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
use Magento\Store\Model\ScopeInterface;
13+
14+
/**
15+
* View model for search
16+
*/
17+
class ConfigProvider implements ArgumentInterface
18+
{
19+
/**
20+
* Suggestions settings config paths
21+
*/
22+
private const SEARCH_SUGGESTION_ENABLED = 'catalog/search/search_suggestion_enabled';
23+
24+
/**
25+
* @var ScopeConfigInterface
26+
*/
27+
private $scopeConfig;
28+
29+
/**
30+
* @param ScopeConfigInterface $scopeConfig
31+
*/
32+
public function __construct(
33+
ScopeConfigInterface $scopeConfig
34+
) {
35+
$this->scopeConfig = $scopeConfig;
36+
}
37+
38+
/**
39+
* Is Search Suggestions Allowed
40+
*
41+
* @return bool
42+
*/
43+
public function isSuggestionsAllowed(): bool
44+
{
45+
return $this->scopeConfig->isSetFlag(
46+
self::SEARCH_SUGGESTION_ENABLED,
47+
ScopeInterface::SCOPE_STORE
48+
);
49+
}
50+
}

app/code/Magento/Search/view/frontend/layout/default.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceContainer name="header-wrapper">
11-
<block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml" />
11+
<block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml">
12+
<arguments>
13+
<argument name="configProvider" xsi:type="object">Magento\Search\ViewModel\ConfigProvider</argument>
14+
</arguments>
15+
</block>
1216
</referenceContainer>
1317
<referenceBlock name="footer_links">
1418
<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="catalog/seo/search_terms" name="search-term-popular-link">

app/code/Magento/Search/view/frontend/templates/form.mini.phtml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
<?php
1010
/** @var $block \Magento\Framework\View\Element\Template */
1111
/** @var $helper \Magento\Search\Helper\Data */
12+
/** @var $configProvider \Magento\Search\ViewModel\ConfigProvider */
1213
$helper = $this->helper(\Magento\Search\Helper\Data::class);
14+
$configProvider = $block->getData('configProvider');
1315
?>
1416
<div class="block block-search">
1517
<div class="block block-title"><strong><?= $block->escapeHtml(__('Search')) ?></strong></div>
@@ -22,12 +24,14 @@ $helper = $this->helper(\Magento\Search\Helper\Data::class);
2224
</label>
2325
<div class="control">
2426
<input id="search"
25-
data-mage-init='{"quickSearch":{
26-
"formSelector":"#search_mini_form",
27-
"url":"<?= $block->escapeUrl($helper->getSuggestUrl())?>",
28-
"destinationSelector":"#search_autocomplete",
29-
"minSearchLength":"<?= $block->escapeHtml($helper->getMinQueryLength()) ?>"}
30-
}'
27+
<?php if ($configProvider->isSuggestionsAllowed()):?>
28+
data-mage-init='{"quickSearch":{
29+
"formSelector":"#search_mini_form",
30+
"url":"<?= $block->escapeUrl($helper->getSuggestUrl())?>",
31+
"destinationSelector":"#search_autocomplete",
32+
"minSearchLength":"<?= $block->escapeHtml($helper->getMinQueryLength()) ?>"}
33+
}'
34+
<?php endif;?>
3135
type="text"
3236
name="<?= $block->escapeHtmlAttr($helper->getQueryParamName()) ?>"
3337
value="<?= /* @noEscape */ $helper->getEscapedQueryText() ?>"

dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\View\LayoutInterface;
1313
use Magento\Search\Model\QueryFactory;
1414
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\Search\ViewModel\ConfigProvider;
1516

1617
class ResultTest extends \PHPUnit\Framework\TestCase
1718
{
@@ -25,16 +26,27 @@ class ResultTest extends \PHPUnit\Framework\TestCase
2526
*/
2627
private $layout;
2728

29+
/**
30+
* @var ConfigProvider
31+
*/
32+
private $configProvider;
33+
2834
/**
2935
* @inheritdoc
3036
*/
3137
protected function setUp(): void
3238
{
3339
$this->objectManager = Bootstrap::getObjectManager();
3440
$this->layout = $this->objectManager->get(LayoutInterface::class);
41+
$this->configProvider = $this->objectManager->get(ConfigProvider::class);
3542
}
3643

37-
public function testSetListOrders()
44+
/**
45+
* Set list orders test
46+
*
47+
* @return void
48+
*/
49+
public function testSetListOrders(): void
3850
{
3951
$this->layout->addBlock(Text::class, 'head');
4052
// The tested block is using head block
@@ -62,6 +74,7 @@ public function testEscapeSearchText(string $searchValue, string $expectedOutput
6274
$searchResultBlock = $this->layout->createBlock(Result::class);
6375
/** @var Template $searchBlock */
6476
$searchBlock = $this->layout->createBlock(Template::class);
77+
$searchBlock->setData(['configProvider' => $this->configProvider]);
6578
$searchBlock->setTemplate('Magento_Search::form.mini.phtml');
6679
/** @var RequestInterface $request */
6780
$request = $this->objectManager->get(RequestInterface::class);

0 commit comments

Comments
 (0)