Skip to content

Commit d2c2c00

Browse files
committed
Fix no results handle layout update
1 parent 158a0fd commit d2c2c00

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

app/code/Magento/CatalogSearch/Controller/Advanced/Result.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ public function execute()
6464

6565
$handles = null;
6666
if ($size == 0) {
67-
$handles = [static::DEFAULT_NO_RESULT_HANDLE];
67+
$this->_view->getPage()->initLayout();
68+
$handles = $this->_view->getLayout()->getUpdate()->getHandles();
69+
$handles[] = static::DEFAULT_NO_RESULT_HANDLE;
6870
}
6971

7072
$this->_view->loadLayout($handles);

app/code/Magento/CatalogSearch/Controller/Result/Index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ public function execute()
9595

9696
$handles = null;
9797
if ($query->getNumResults() == 0) {
98-
$handles = [static::DEFAULT_NO_RESULT_HANDLE];
98+
$this->_view->getPage()->initLayout();
99+
$handles = $this->_view->getLayout()->getUpdate()->getHandles();
100+
$handles[] = static::DEFAULT_NO_RESULT_HANDLE;
99101
}
100102

101103
if (empty($getAdditionalRequestParameters) &&

app/code/Magento/CatalogSearch/Test/Unit/Controller/Advanced/ResultTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ public function testUrlSetOnException()
139139
/** @var \Magento\CatalogSearch\Controller\Advanced\Result $instance */
140140
$instance = $objectManager->getObject(
141141
\Magento\CatalogSearch\Controller\Advanced\Result::class,
142-
['context' => $contextMock,
143-
'catalogSearchAdvanced' => $catalogSearchAdvanced,
144-
'urlFactory' => $urlFactoryMock
142+
[
143+
'context' => $contextMock,
144+
'catalogSearchAdvanced' => $catalogSearchAdvanced,
145+
'urlFactory' => $urlFactoryMock
145146
]
146147
);
147148
$this->assertEquals($redirectResultMock, $instance->execute());
@@ -151,10 +152,25 @@ public function testNoResultsHandle()
151152
{
152153
$expectedQuery = 'notExistTerm';
153154

154-
$view = $this->createPartialMock(\Magento\Framework\App\View::class, ['loadLayout', 'renderLayout']);
155+
$update = $this->createPartialMock(\Magento\Framework\View\Model\Layout\Merge::class, ['getHandles']);
156+
$update->expects($this->once())->method('getHandles')->will($this->returnValue([]));
157+
158+
$layout = $this->createPartialMock(\Magento\Framework\View\Result\Layout::class, ['getUpdate']);
159+
$layout->expects($this->once())->method('getUpdate')->will($this->returnValue($update));
160+
161+
$page = $this->createPartialMock(\Magento\Framework\View\Result\Page::class, ['initLayout']);
162+
163+
$view = $this->createPartialMock(
164+
\Magento\Framework\App\View::class,
165+
['loadLayout', 'renderLayout', 'getPage', 'getLayout']
166+
);
167+
155168
$view->expects($this->once())->method('loadLayout')
156169
->with([\Magento\CatalogSearch\Controller\Advanced\Result::DEFAULT_NO_RESULT_HANDLE]);
157170

171+
$view->expects($this->once())->method('getPage')->will($this->returnValue($page));
172+
$view->expects($this->once())->method('getLayout')->will($this->returnValue($layout));
173+
158174
$request = $this->createPartialMock(\Magento\Framework\App\Console\Request::class, ['getQueryValue']);
159175
$request->expects($this->once())->method('getQueryValue')->will($this->returnValue($expectedQuery));
160176

0 commit comments

Comments
 (0)