Skip to content

Commit 49fdfae

Browse files
committed
refactor the code on get toolbar block from layout, fix condition on using the mode layout configuration
1 parent 9dbe444 commit 49fdfae

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ private function getDefaultListingMode()
163163

164164
// layout config mode
165165
$mode = $this->getData('mode');
166-
if (!$mode && !isset($availableModes[$mode])) {
166+
167+
if (!$mode || !isset($availableModes[$mode])) {
167168
// default config mode
168169
$mode = $defaultToolbar->getCurrentMode();
169170
}
@@ -194,13 +195,7 @@ protected function _beforeToHtml()
194195
*/
195196
private function addToolbarBlock(Collection $collection)
196197
{
197-
$toolbarLayout = false;
198-
199-
$blockName = $this->getToolbarBlockName();
200-
201-
if ($blockName) {
202-
$toolbarLayout = $this->getLayout()->getBlock($blockName);
203-
}
198+
$toolbarLayout = $this->getToolbarFromLayout();
204199

205200
if ($toolbarLayout) {
206201
$this->configureToolbar($toolbarLayout, $collection);
@@ -214,11 +209,7 @@ private function addToolbarBlock(Collection $collection)
214209
*/
215210
public function getToolbarBlock()
216211
{
217-
$blockName = $this->getToolbarBlockName();
218-
219-
if ($blockName) {
220-
$block = $this->getLayout()->getBlock($blockName);
221-
}
212+
$block = $this->getToolbarFromLayout();
222213

223214
if (!$block) {
224215
$block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, uniqid(microtime()));
@@ -227,6 +218,24 @@ public function getToolbarBlock()
227218
return $block;
228219
}
229220

221+
/**
222+
* Get toolbar block from layout
223+
*
224+
* @return bool|Toolbar
225+
*/
226+
private function getToolbarFromLayout()
227+
{
228+
$blockName = $this->getToolbarBlockName();
229+
230+
$toolbarLayout = false;
231+
232+
if ($blockName) {
233+
$toolbarLayout = $this->getLayout()->getBlock($blockName);
234+
}
235+
236+
return $toolbarLayout;
237+
}
238+
230239
/**
231240
* Retrieve additional blocks html
232241
*

0 commit comments

Comments
 (0)