/**
  * @param $isAvailable
  * @param $isFlatEnabled
  * @param $isValid
  * @param $result
  * @dataProvider isAvailableDataProvider
  */
 public function testIsAvailable($isAvailable, $isFlatEnabled, $isValid, $result)
 {
     $this->flatIndexerMock->expects($this->any())->method('load')->with('catalog_category_flat');
     $this->flatIndexerMock->expects($this->any())->method('isValid')->will($this->returnValue($isValid));
     $this->indexerRegistryMock->expects($this->any())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->flatIndexerMock));
     $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->with('catalog/frontend/flat_catalog_category')->will($this->returnValue($isFlatEnabled));
     $this->model = new \Magento\Catalog\Model\Indexer\Category\Flat\State($this->scopeConfigMock, $this->indexerRegistryMock, $isAvailable);
     $this->assertEquals($result, $this->model->isAvailable());
 }
Example #2
0
 /**
  * Initialize resource mode
  *
  * @return void
  */
 protected function _construct()
 {
     // If Flat Index enabled then use it but only on frontend
     if ($this->flatState->isAvailable()) {
         $this->_init('Magento\\Catalog\\Model\\Resource\\Category\\Flat');
         $this->_useFlatResource = true;
     } else {
         $this->_init('Magento\\Catalog\\Model\\Resource\\Category');
     }
 }
Example #3
0
 /**
  * Render category to html
  *
  * @param Category $category
  * @param int $level Nesting level number
  * @param boolean $isLast Whether ot not this item is last, affects list item class
  * @param boolean $isFirst Whether ot not this item is first, affects list item class
  * @param boolean $isOutermost Whether ot not this item is outermost, affects list item class
  * @param string $outermostItemClass Extra class of outermost list items
  * @param string $childrenWrapClass If specified wraps children list in div with this class
  * @param boolean $noEventAttributes Whether ot not to add on* attributes to list item
  * @return string
  */
 protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false, $isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
 {
     if (!$category->getIsActive()) {
         return '';
     }
     // get all children
     if ($this->flatState->isAvailable()) {
         $children = (array) $category->getChildrenNodes();
     } else {
         $children = $category->getChildren();
     }
     // select active children
     $activeChildren = array();
     foreach ($children as $child) {
         if ($child->getIsActive()) {
             $activeChildren[] = $child;
         }
     }
     $activeChildrenCount = count($activeChildren);
     $hasActiveChildren = $activeChildrenCount > 0;
     // prepare list item html classes
     $classes = array();
     $classes[] = 'level' . $level;
     $classes[] = 'nav-' . $this->_getItemPosition($level);
     if ($this->isCategoryActive($category)) {
         $classes[] = 'active';
     }
     $linkClass = '';
     if ($isOutermost && $outermostItemClass) {
         $classes[] = $outermostItemClass;
         $linkClass = ' class="' . $outermostItemClass . '"';
     }
     if ($isFirst) {
         $classes[] = 'first';
     }
     if ($isLast) {
         $classes[] = 'last';
     }
     if ($hasActiveChildren) {
         $classes[] = 'parent';
     }
     // prepare list item attributes
     $attributes = array();
     if (count($classes) > 0) {
         $attributes['class'] = implode(' ', $classes);
     }
     if ($hasActiveChildren && !$noEventAttributes) {
         $attributes['onmouseover'] = 'toggleMenu(this,1)';
         $attributes['onmouseout'] = 'toggleMenu(this,0)';
     }
     // assemble list item with attributes
     $htmlLi = '<li';
     foreach ($attributes as $attrName => $attrValue) {
         $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
     }
     $htmlLi .= '>';
     $html = array();
     $html[] = $htmlLi;
     $html[] = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '>';
     $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
     $html[] = '</a>';
     // render children
     $htmlChildren = '';
     $j = 0;
     foreach ($activeChildren as $child) {
         $htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
         $j++;
     }
     if (!empty($htmlChildren)) {
         if ($childrenWrapClass) {
             $html[] = '<div class="' . $childrenWrapClass . '">';
         }
         $html[] = '<ul class="level' . $level . '">';
         $html[] = $htmlChildren;
         $html[] = '</ul>';
         if ($childrenWrapClass) {
             $html[] = '</div>';
         }
     }
     $html[] = '</li>';
     $html = implode("\n", $html);
     return $html;
 }