Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search Navigation not visible if default category has "Display Mode" other than "page" #39555

Open
wants to merge 8 commits into
base: 2.4-develop
Choose a base branch
from
18 changes: 11 additions & 7 deletions app/code/Magento/LayeredNavigation/Block/Navigation.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2024 Adobe
* All Rights Reserved.
*/
namespace Magento\LayeredNavigation\Block;

use Magento\Framework\View\Element\Template;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Block\Product\ProductList\Toolbar;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Framework\App\Request\Http;
use Magento\Framework\View\Element\Template;

/**
* Catalog layered navigation view block
@@ -23,8 +24,6 @@ class Navigation extends \Magento\Framework\View\Element\Template
private const PRODUCT_LISTING_TOOLBAR_BLOCK = 'product_list_toolbar';

/**
* Catalog layer
*
* @var \Magento\Catalog\Model\Layer
*/
protected $_catalogLayer;
@@ -122,7 +121,12 @@ public function getFilters()
*/
public function canShowBlock()
{
return $this->getLayer()->getCurrentCategory()->getDisplayMode() !== \Magento\Catalog\Model\Category::DM_PAGE
/** @var Http $request */
$request = $this->getRequest();
return (
$this->getLayer()->getCurrentCategory()->getDisplayMode() !== \Magento\Catalog\Model\Category::DM_PAGE
|| $request->getRouteName() === 'catalogsearch'
)
&& $this->visibilityFlag->isEnabled($this->getLayer(), $this->getFilters());
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2024 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

@@ -12,6 +12,7 @@
use Magento\Catalog\Model\Layer\AvailabilityFlagInterface;
use Magento\Catalog\Model\Layer\FilterList;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Framework\App\Request\Http;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\View\LayoutInterface;
@@ -41,6 +42,11 @@ class NavigationTest extends TestCase
*/
protected $visibilityFlagMock;

/**
* @var MockObject
*/
protected $requestMock;

/**
* @var Navigation
*/
@@ -54,6 +60,10 @@ protected function setUp(): void
$this->catalogLayerMock = $this->createMock(Layer::class);
$this->filterListMock = $this->createMock(FilterList::class);
$this->visibilityFlagMock = $this->getMockForAbstractClass(AvailabilityFlagInterface::class);
$this->requestMock = $this->getMockBuilder(Http::class)
->disableOriginalConstructor()
->onlyMethods(['getRouteName'])
->getMock();

/** @var MockObject|Resolver $layerResolver */
$layerResolver = $this->getMockBuilder(Resolver::class)
@@ -70,7 +80,8 @@ protected function setUp(): void
[
'layerResolver' => $layerResolver,
'filterList' => $this->filterListMock,
'visibilityFlag' => $this->visibilityFlagMock
'visibilityFlag' => $this->visibilityFlagMock,
'_request' => $this->requestMock
]
);
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
@@ -137,7 +148,7 @@ public function testCanShowBlock(): void
* @return void
* @dataProvider canShowBlockDataProvider
*/
public function testCanShowBlockWithDifferentDisplayModes(string $mode, bool $result): void
public function testCanShowBlockWithDifferentDisplayModes(string $mode, string $routeName, bool $result): void
{
$filters = ['To' => 'be', 'or' => 'not', 'to' => 'be'];

@@ -154,6 +165,8 @@ public function testCanShowBlockWithDifferentDisplayModes(string $mode, bool $re

$category = $this->createMock(Category::class);
$this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category);
$this->requestMock->expects($this->any())->method('getRouteName')->willReturn($routeName);

$category->expects($this->once())->method('getDisplayMode')->willReturn($mode);
$this->assertEquals($result, $this->model->canShowBlock());
}
@@ -166,14 +179,32 @@ public static function canShowBlockDataProvider(): array
return [
[
Category::DM_PRODUCT,
'catalog',
true
],
[
Category::DM_PAGE,
'catalog',
false
],
[
Category::DM_MIXED,
'catalog',
true
],
[
Category::DM_PRODUCT,
'catalogsearch',
true
],
[
Category::DM_PAGE,
'catalogsearch',
true
],
[
Category::DM_MIXED,
'catalogsearch',
true
],
];