*
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();
$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){
return $this->getParentIds($id);
}
else{
}
//return $this->getParentIds($id);
//return array_intersect($current_cats, $this->getCategoriesFromCache())
}
public function renderBreadCrumps($current_cats){
$i=1;
$script = '<script type="application/ld+json">{
"@context": "https://schema.org",
"@type":"BreadcrumbList",
"itemListElement": [
{"@type":"ListItem","position":'.$i.',"item":{"@id":"https://bookland.com.pl/","name":"Bookland"}},';
foreach ($this->getBreadCrumpsCatIds($current_cats) as $value) {
$i++;
$script .='{"@type":"ListItem","position":'.$i.',"item":{"@id":"'.$value['url'].'","name":"'.$value['name'].'"}},';
}
$script=rtrim($script,',');
$script.=']}</script>';
return $script;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}