123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * Catalog layered navigation view block
- *
- * @author Magento Core Team <core@magentocommerce.com>
- */
- namespace Magento\LayeredNavigation\Block;
- use Magento\Framework\View\Element\Template;
- /**
- * @api
- * @since 100.0.2
- */
- class Navigation extends \Magento\Framework\View\Element\Template
- {
- /**
- * Catalog layer
- *
- * @var \Magento\Catalog\Model\Layer
- */
- protected $_catalogLayer;
- /**
- * @var \Magento\Catalog\Model\Layer\FilterList
- */
- protected $filterList;
- /**
- * @var \Magento\Catalog\Model\Layer\AvailabilityFlagInterface
- */
- protected $visibilityFlag;
- /**
- * @param Template\Context $context
- * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
- * @param \Magento\Catalog\Model\Layer\FilterList $filterList
- * @param \Magento\Catalog\Model\Layer\AvailabilityFlagInterface $visibilityFlag
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Catalog\Model\Layer\Resolver $layerResolver,
- \Magento\Catalog\Model\Layer\FilterList $filterList,
- \Magento\Catalog\Model\Layer\AvailabilityFlagInterface $visibilityFlag,
- array $data = []
- ) {
- $this->_catalogLayer = $layerResolver->get();
- $this->filterList = $filterList;
- $this->visibilityFlag = $visibilityFlag;
- parent::__construct($context, $data);
- }
- /**
- * Apply layer
- *
- * @return $this
- */
- protected function _prepareLayout()
- {
- foreach ($this->filterList->getFilters($this->_catalogLayer) as $filter) {
- $filter->apply($this->getRequest());
- }
- $this->getLayer()->apply();
- return parent::_prepareLayout();
- }
- /**
- * Get layer object
- *
- * @return \Magento\Catalog\Model\Layer
- */
- public function getLayer()
- {
- return $this->_catalogLayer;
- }
- /**
- * Get layered navigation state html
- *
- * @return string
- */
- public function getStateHtml()
- {
- return $this->getChildHtml('state');
- }
- /**
- * Get all layer filters
- *
- * @return array
- */
- public function getFilters()
- {
- return $this->filterList->getFilters($this->_catalogLayer);
- }
- /**
- * Check availability display layer block
- *
- * @return bool
- */
- public function canShowBlock()
- {
- return $this->visibilityFlag->isEnabled($this->getLayer(), $this->getFilters());
- }
- /**
- * Get url for 'Clear All' link
- *
- * @return string
- */
- public function getClearUrl()
- {
- return $this->getChildBlock('state')->getClearUrl();
- }
- }
|