70 private $layerResolver;
94 \
Magento\Catalog\Model\Design $catalogDesign,
95 \
Magento\Catalog\Model\Session $catalogSession,
96 \
Magento\Framework\Registry $coreRegistry,
104 parent::__construct($context);
106 $this->_catalogDesign = $catalogDesign;
107 $this->_catalogSession = $catalogSession;
108 $this->_coreRegistry = $coreRegistry;
112 $this->layerResolver = $layerResolver;
123 $categoryId = (int)$this->
getRequest()->getParam(
'id',
false);
129 $category = $this->categoryRepository->get($categoryId, $this->_storeManager->getStore()->getId());
133 if (!$this->_objectManager->get(\
Magento\Catalog\Helper\Category::class)->canShow(
$category)) {
136 $this->_catalogSession->setLastVisitedCategoryId(
$category->getId());
137 $this->_coreRegistry->register(
'current_category',
$category);
139 $this->_eventManager->dispatch(
140 'catalog_controller_category_init_after',
141 [
'category' =>
$category,
'controller_action' => $this]
143 }
catch (\
Magento\Framework\Exception\LocalizedException $e) {
144 $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
160 if ($this->_request->getParam(\
Magento\Framework\
App\ActionInterface::PARAM_NAME_URL_ENCODED)) {
161 return $this->resultRedirectFactory->create()->setUrl($this->
_redirect->getRedirectUrl());
170 $this->_catalogDesign->applyCustomDesign(
$settings->getCustomDesign());
173 $this->_catalogSession->setLastViewedCategoryId(
$category->getId());
175 $page = $this->resultPageFactory->create();
183 $type = $hasChildren ?
'layered' :
'layered_without_children';
185 $type = $hasChildren ?
'default' :
'default_without_children';
190 $parentType = strtok(
$type,
'_');
191 $page->addPageLayoutHandles([
'type' => $parentType],
null,
false);
193 $page->addPageLayoutHandles([
'type' =>
$type],
null,
false);
197 $layoutUpdates =
$settings->getLayoutUpdates();
198 if ($layoutUpdates && is_array($layoutUpdates)) {
199 foreach ($layoutUpdates as $layoutUpdate) {
200 $page->addUpdate($layoutUpdate);
201 $page->addPageLayoutHandles([
'layout_update' => md5($layoutUpdate)],
null,
false);
205 $page->getConfig()->addBodyClass(
'page-products')
206 ->addBodyClass(
'categorypath-' . $this->categoryUrlPathGenerator->getUrlPath(
$category))
207 ->addBodyClass(
'category-' .
$category->getUrlKey());
211 return $this->resultForwardFactory->create()->forward(
'noroute');
_redirect($path, $arguments=[])
elseif(isset( $params[ 'redirect_parent']))
$categoryUrlPathGenerator
const CATALOG_LAYER_CATEGORY
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry $coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository)