Skip to content

Commit 7cd5958

Browse files
ENGCOM-586: #7765: Filter block on category is still present also mode is to just show 'static block' #1159
- Merge Pull Request magento-engcom/magento2ce#1159 from RomaKis/magento2ce:7765 - Merged commits: 1. 39e0fd9
2 parents 30462cd + 39e0fd9 commit 7cd5958

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

app/code/Magento/LayeredNavigation/Block/Navigation.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public function getFilters()
107107
*/
108108
public function canShowBlock()
109109
{
110-
return $this->visibilityFlag->isEnabled($this->getLayer(), $this->getFilters());
110+
return $this->getLayer()->getCurrentCategory()->getDisplayMode() !== \Magento\Catalog\Model\Category::DM_PAGE
111+
&& $this->visibilityFlag->isEnabled($this->getLayer(), $this->getFilters());
111112
}
112113

113114
/**

app/code/Magento/LayeredNavigation/Test/Unit/Block/NavigationTest.php

+55
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\LayeredNavigation\Test\Unit\Block;
88

9+
use Magento\Catalog\Model\Category;
10+
911
class NavigationTest extends \PHPUnit\Framework\TestCase
1012
{
1113
/**
@@ -98,9 +100,62 @@ public function testCanShowBlock()
98100
->method('isEnabled')
99101
->with($this->catalogLayerMock, $filters)
100102
->will($this->returnValue($enabled));
103+
104+
$category = $this->createMock(Category::class);
105+
$this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category);
106+
$category->expects($this->once())->method('getDisplayMode')->willReturn(Category::DM_PRODUCT);
107+
101108
$this->assertEquals($enabled, $this->model->canShowBlock());
102109
}
103110

111+
/**
112+
* Test canShowBlock() with different category display types.
113+
*
114+
* @param string $mode
115+
* @param bool $result
116+
*
117+
* @dataProvider canShowBlockDataProvider
118+
*/
119+
public function testCanShowBlockWithDifferentDisplayModes(string $mode, bool $result)
120+
{
121+
$filters = ['To' => 'be', 'or' => 'not', 'to' => 'be'];
122+
123+
$this->filterListMock->expects($this->atLeastOnce())->method('getFilters')
124+
->with($this->catalogLayerMock)
125+
->will($this->returnValue($filters));
126+
$this->assertEquals($filters, $this->model->getFilters());
127+
128+
$this->visibilityFlagMock
129+
->expects($this->any())
130+
->method('isEnabled')
131+
->with($this->catalogLayerMock, $filters)
132+
->will($this->returnValue(true));
133+
134+
$category = $this->createMock(Category::class);
135+
$this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category);
136+
$category->expects($this->once())->method('getDisplayMode')->willReturn($mode);
137+
138+
$this->assertEquals($result, $this->model->canShowBlock());
139+
}
140+
141+
public function canShowBlockDataProvider()
142+
{
143+
return [
144+
[
145+
Category::DM_PRODUCT,
146+
true,
147+
],
148+
[
149+
Category::DM_PAGE,
150+
false,
151+
],
152+
[
153+
Category::DM_MIXED,
154+
true,
155+
],
156+
];
157+
}
158+
104159
public function testGetClearUrl()
105160
{
106161
$this->filterListMock->expects($this->any())->method('getFilters')->will($this->returnValue([]));

0 commit comments

Comments
 (0)