|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 |
| - |
7 |
| -/** |
8 |
| - * Catalog layered navigation view block |
9 |
| - * |
10 |
| - * @author Magento Core Team <[email protected]> |
11 |
| - */ |
12 | 6 | namespace Magento\LayeredNavigation\Block;
|
13 | 7 |
|
14 | 8 | use Magento\Framework\View\Element\Template;
|
| 9 | +use Magento\Catalog\Model\ResourceModel\Product\Collection; |
| 10 | +use Magento\Catalog\Block\Product\ProductList\Toolbar; |
15 | 11 |
|
16 | 12 | /**
|
| 13 | + * Catalog layered navigation view block |
| 14 | + * |
17 | 15 | * @api
|
18 | 16 | * @since 100.0.2
|
19 | 17 | */
|
20 | 18 | class Navigation extends \Magento\Framework\View\Element\Template
|
21 | 19 | {
|
| 20 | + /** |
| 21 | + * Product listing toolbar block name |
| 22 | + */ |
| 23 | + private const PRODUCT_LISTING_TOOLBAR_BLOCK = 'product_list_toolbar'; |
| 24 | + |
22 | 25 | /**
|
23 | 26 | * Catalog layer
|
24 | 27 | *
|
@@ -67,9 +70,20 @@ protected function _prepareLayout()
|
67 | 70 | $filter->apply($this->getRequest());
|
68 | 71 | }
|
69 | 72 | $this->getLayer()->apply();
|
| 73 | + |
70 | 74 | return parent::_prepareLayout();
|
71 | 75 | }
|
72 | 76 |
|
| 77 | + /** |
| 78 | + * @inheritdoc |
| 79 | + */ |
| 80 | + protected function _beforeToHtml() |
| 81 | + { |
| 82 | + $this->configureToolbarBlock(); |
| 83 | + |
| 84 | + return parent::_beforeToHtml(); |
| 85 | + } |
| 86 | + |
73 | 87 | /**
|
74 | 88 | * Get layer object
|
75 | 89 | *
|
@@ -119,4 +133,20 @@ public function getClearUrl()
|
119 | 133 | {
|
120 | 134 | return $this->getChildBlock('state')->getClearUrl();
|
121 | 135 | }
|
| 136 | + |
| 137 | + /** |
| 138 | + * Configures the Toolbar block |
| 139 | + * |
| 140 | + * @return void |
| 141 | + */ |
| 142 | + private function configureToolbarBlock(): void |
| 143 | + { |
| 144 | + /** @var Toolbar $toolbarBlock */ |
| 145 | + $toolbarBlock = $this->getLayout()->getBlock(self::PRODUCT_LISTING_TOOLBAR_BLOCK); |
| 146 | + if ($toolbarBlock) { |
| 147 | + /** @var Collection $collection */ |
| 148 | + $collection = $this->getLayer()->getProductCollection(); |
| 149 | + $toolbarBlock->setCollection($collection); |
| 150 | + } |
| 151 | + } |
122 | 152 | }
|
0 commit comments