示例#1
0
 /**
  * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $subject
  * @param callable $proceed
  * @param \Magento\Framework\Model\AbstractModel $group
  *
  * @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundSave(\Magento\Framework\Model\ResourceModel\Db\AbstractDb $subject, \Closure $proceed, \Magento\Framework\Model\AbstractModel $group)
 {
     $needInvalidating = $this->validate($group);
     $objectResource = $proceed($group);
     if ($needInvalidating && $this->state->isFlatEnabled()) {
         $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->invalidate();
     }
     return $objectResource;
 }
示例#2
0
 /**
  * @param \Magento\Framework\Model\Resource\Db\AbstractDb $subject
  * @param callable $proceed
  * @param \Magento\Framework\Model\AbstractModel $group
  *
  * @return \Magento\Framework\Model\Resource\Db\AbstractDb
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundSave(\Magento\Framework\Model\Resource\Db\AbstractDb $subject, \Closure $proceed, \Magento\Framework\Model\AbstractModel $group)
 {
     $needInvalidating = $this->validate($group);
     $objectResource = $proceed($group);
     if ($needInvalidating && $this->state->isFlatEnabled()) {
         $this->getIndexer()->invalidate();
     }
     return $objectResource;
 }
示例#3
0
 /**
  *  Unset indexer data in configuration if flat is disabled
  *
  * @param \Magento\Indexer\Model\Config\Data $subject
  * @param callable $proceed
  * @param string $path
  * @param mixed $default
  *
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGet(\Magento\Indexer\Model\Config\Data $subject, \Closure $proceed, $path = null, $default = null)
 {
     $data = $proceed($path, $default);
     if (!$this->state->isFlatEnabled()) {
         $indexerId = \Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID;
         if (!$path && isset($data[$indexerId])) {
             unset($data[$indexerId]);
         } elseif ($path) {
             list($firstKey, ) = explode('/', $path);
             if ($firstKey == $indexerId) {
                 $data = $default;
             }
         }
     }
     return $data;
 }
 /**
  * Recursively adds categories to top menu
  *
  * @param \Magento\Framework\Data\Tree\Node\Collection|array $categories
  * @param \Magento\Framework\Data\Tree\Node $parentCategoryNode
  * @param \Magento\Theme\Block\Html\Topmenu $block
  * @return void
  */
 protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block)
 {
     foreach ($categories as $category) {
         if (!$category->getIsActive()) {
             continue;
         }
         $block->addIdentity(\Magento\Catalog\Model\Category::CACHE_TAG . '_' . $category->getId());
         $tree = $parentCategoryNode->getTree();
         $categoryData = $this->menuCategoryData->getMenuCategoryData($category);
         $categoryNode = new \Magento\Framework\Data\Tree\Node($categoryData, 'id', $tree, $parentCategoryNode);
         $parentCategoryNode->addChild($categoryNode);
         if ($this->categoryFlatState->isFlatEnabled() && $category->getUseFlatResource()) {
             $subcategories = (array) $category->getChildrenNodes();
         } else {
             $subcategories = $category->getChildren();
         }
         $this->_addCategoriesToMenu($subcategories, $categoryNode, $block);
     }
 }
 /**
  * Get current category
  *
  * @param \Magento\Catalog\Model\Category $category
  *
  * @return Category
  */
 public function isActive($category)
 {
     $activeCategory = $this->_coreRegistry->registry('current_category');
     $activeProduct = $this->_coreRegistry->registry('current_product');
     if (!$activeCategory) {
         // Check if we're on a product page
         if ($activeProduct !== null) {
             return in_array($category->getId(), $activeProduct->getCategoryIds());
         }
         return false;
     }
     // Check if this is the active category
     if ($this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource() and $category->getId() == $activeCategory->getId()) {
         return true;
     }
     // Check if a subcategory of this category is active
     $childrenIds = $category->getAllChildren(true);
     if (!is_null($childrenIds) and in_array($activeCategory->getId(), $childrenIds)) {
         return true;
     }
     // Fallback - If Flat categories is not enabled the active category does not give an id
     return $category->getName() == $activeCategory->getName() ? true : false;
 }
示例#6
0
 /**
  * Init indexing process after category save
  *
  * @return void
  */
 public function reindex()
 {
     if ($this->flatState->isFlatEnabled()) {
         $flatIndexer = $this->indexerRegistry->get(Indexer\Category\Flat\State::INDEXER_ID);
         if (!$flatIndexer->isScheduled()) {
             $flatIndexer->reindexRow($this->getId());
         }
     }
     $affectedProductIds = $this->getAffectedProductIds();
     $productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
     if (!$productIndexer->isScheduled() && !empty($affectedProductIds)) {
         $productIndexer->reindexList($this->getPathIds());
     }
 }
 /**
  * Init indexing process after category save
  *
  * @return void
  */
 public function reindex()
 {
     if ($this->flatState->isFlatEnabled()) {
         $flatIndexer = $this->indexerRegistry->get(Indexer\Category\Flat\State::INDEXER_ID);
         if (!$flatIndexer->isScheduled()) {
             $flatIndexer->reindexRow($this->getId());
         }
     }
     $productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
     if (!$productIndexer->isScheduled() && (!empty($this->getAffectedProductIds()) || $this->dataHasChangedFor('is_anchor'))) {
         $productIndexer->reindexList($this->getPathIds());
     }
 }
示例#8
0
 public function testIsFlatEnabled()
 {
     $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with('catalog/frontend/flat_catalog_category')->will($this->returnValue(true));
     $this->model = new \Magento\Catalog\Model\Indexer\Category\Flat\State($this->scopeConfigMock, $this->indexerRegistryMock);
     $this->assertEquals(true, $this->model->isFlatEnabled());
 }