* Cache category ids FOR product breadcrumps; */ public function cacheCategoryIds(){ $identifier='network_cache_category_ids'; $this->cache = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Framework\App\CacheInterface'); if(!$this->cache->load($identifier)){ $data=$this->getCategoriesToCache(); $tags=array(); $this->cache->save($data, $identifier, $tags, 60*5); } return $this->cache->load($identifier); } public function getCategoriesToCache(){ $connection = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\App\ResourceConnection')->getConnection('\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION'); $result = $connection->fetchCol("SELECT entity_id FROM m2_catalog_category_entity_text where attribute_id='161' and value!='' and store_id='0'; "); return $this->getSerializer()->serialize($result); } public function getCategoriesFromCache(){ return $this->getSerializer()->unserialize($this->cacheCategoryIds()); } private function getSerializer() { if ($this->serializer === null) { $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() ->get('\Magento\Framework\Serialize\Serializer\Json'); } return $this->serializer; } public function getParentIds($categoryId = false) { $categoryFactory = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Catalog\Model\CategoryFactory'); $categoryHelper = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Catalog\Helper\Category'); $categoryRepository = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Catalog\Model\CategoryRepository'); $category = $categoryFactory->create()->load($categoryId); foreach ($category->getParentCategories() as $cat) { $ids[]=array('id'=> $cat->getId(), 'name'=> $cat->getName(), 'url'=> explode('?', $cat->getUrl())[0]); } return $ids; } public function getBreadCrumpsCatIds($current_cats){ $data = array_intersect($current_cats, $this->getCategoriesFromCache()); if(!empty($data)){ $id = max($data); return $this->getParentIds($id); } else{ return array(); } //return $this->getParentIds($id); //return array_intersect($current_cats, $this->getCategoriesFromCache()) } public function renderBreadCrumps($current_cats){ $i=1; $script = ''; return $script; }