Exemplo n.º 1
0
 /**
  * Initialize categories ID to text-path hash.
  *
  * @return $this
  */
 protected function _initCategories()
 {
     $collection = $this->_categoryColFactory->create()->addNameToResult();
     /* @var $collection \Magento\Catalog\Model\Resource\Category\Collection */
     foreach ($collection as $category) {
         $structure = preg_split('#/+#', $category->getPath());
         $pathSize = count($structure);
         if ($pathSize > 1) {
             $path = array();
             for ($i = 1; $i < $pathSize; $i++) {
                 $path[] = $collection->getItemById($structure[$i])->getName();
             }
             $this->_rootCategories[$category->getId()] = array_shift($path);
             if ($pathSize > 2) {
                 $this->_categories[$category->getId()] = implode('/', $path);
             }
         }
     }
     return $this;
 }