<?php /** * Copyright © 2016 Ihor Vansach (ihor@magefan.com). All rights reserved. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php). * * Glory to Ukraine! Glory to the heroes! */ namespace Magefan\Blog\Controller\Category; /** * Blog category view */ class View extends \Magento\Framework\App\Action\Action { /** * Store manager * * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManager; /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Store\Model\StoreManagerInterface $storeManager */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager ) { parent::__construct($context); $this->_storeManager = $storeManager; } /** * View blog category action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $category = $this->_initCategory(); if (!$category) { $this->_forward('index', 'noroute', 'cms'); return; } $this->_objectManager->get('\Magento\Framework\Registry') ->register('current_blog_category', $category); $resultPage = $this->_objectManager->get('Magefan\Blog\Helper\Page') ->prepareResultPage($this, $category); return $resultPage; } /** * Init category * * @return \Magefan\Blog\Model\category || false */ protected function _initCategory() { $id = $this->getRequest()->getParam('id'); $storeId = $this->_storeManager->getStore()->getId(); $category = $this->_objectManager->create('Magefan\Blog\Model\Category')->load($id); if (!$category->isVisibleOnStore($storeId)) { return false; } $category->setStoreId($storeId); return $category; } }