Esempio n. 1
0
 /**
  * Initialize requested category object
  *
  * @return \Magento\Catalog\Model\Category
  */
 protected function _initCategory()
 {
     $categoryId = (int) $this->getRequest()->getParam('id', false);
     if (!$categoryId) {
         return false;
     }
     /** @var \Magento\Catalog\Model\Category $category */
     $category = $this->_categoryFactory->create()->setStoreId($this->_storeManager->getStore()->getId())->load($categoryId);
     if (!$this->_objectManager->get('Magento\\Catalog\\Helper\\Category')->canShow($category)) {
         return false;
     }
     $this->_catalogSession->setLastVisitedCategoryId($category->getId());
     $this->_coreRegistry->register('current_category', $category);
     try {
         $this->_eventManager->dispatch('catalog_controller_category_init_after', array('category' => $category, 'controller_action' => $this));
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         return false;
     }
     return $category;
 }
Esempio n. 2
0
 /**
  * Initialize requested category object
  *
  * @return \Magento\Catalog\Model\Category
  */
 protected function _initCategory()
 {
     $categoryId = (int) $this->getRequest()->getParam('id', false);
     if (!$categoryId) {
         return false;
     }
     try {
         $category = $this->categoryRepository->get($categoryId, $this->_storeManager->getStore()->getId());
     } catch (NoSuchEntityException $e) {
         return false;
     }
     if (!$this->_objectManager->get('Magento\\Catalog\\Helper\\Category')->canShow($category)) {
         return false;
     }
     $this->_catalogSession->setLastVisitedCategoryId($category->getId());
     $this->_coreRegistry->register('current_category', $category);
     try {
         $this->_eventManager->dispatch('catalog_controller_category_init_after', ['category' => $category, 'controller_action' => $this]);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         return false;
     }
     return $category;
 }