/** * @return $this */ protected function _prepareLayout() { parent::_prepareLayout(); $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Breadcrumbs'); $category = $this->getCurrentCategory(); if ($category) { $title = $category->getMetaTitle(); if ($title) { $this->pageConfig->getTitle()->set($title); } $description = $category->getMetaDescription(); if ($description) { $this->pageConfig->setDescription($description); } $keywords = $category->getMetaKeywords(); if ($keywords) { $this->pageConfig->setKeywords($keywords); } if ($this->_categoryHelper->canUseCanonicalTag()) { $this->pageConfig->addRemotePageAsset($category->getUrl(), 'canonical', ['attributes' => ['rel' => 'canonical']]); } $pageMainTitle = $this->getLayout()->getBlock('page.main.title'); if ($pageMainTitle) { $pageMainTitle->setPageTitle($this->getCurrentCategory()->getName()); } } return $this; }
/** * @return $this */ protected function _prepareLayout() { parent::_prepareLayout(); $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Breadcrumbs'); $headBlock = $this->getLayout()->getBlock('head'); $category = $this->getCurrentCategory(); if ($headBlock && $category) { $title = $category->getMetaTitle(); if ($title) { $headBlock->setTitle($title); } $description = $category->getMetaDescription(); if ($description) { $headBlock->setDescription($description); } $keywords = $category->getMetaKeywords(); if ($keywords) { $headBlock->setKeywords($keywords); } //@todo: move canonical link to separate block if ($this->_categoryHelper->canUseCanonicalTag() && !$headBlock->getChildBlock('magento-page-head-category-canonical-link')) { $headBlock->addChild('magento-page-head-category-canonical-link', 'Magento\\Theme\\Block\\Html\\Head\\Link', array('url' => $category->getUrl(), 'properties' => array('attributes' => array('rel' => 'canonical')))); } /** * want to show rss feed in the url */ if ($this->isRssCatalogEnable() && $this->isTopCategory()) { $title = __('%1 RSS Feed', $this->getCurrentCategory()->getName()); $headBlock->addRss($title, $this->getRssLink()); } $pageMainTitle = $this->getLayout()->getBlock('page.main.title'); if ($pageMainTitle) { $pageMainTitle->setPageTitle($this->getCurrentCategory()->getName()); } } return $this; }
/** * @magentoConfigFixture current_store catalog/seo/category_canonical_tag 1 */ public function testCanUseCanonicalTag() { $this->assertEquals(1, $this->_helper->canUseCanonicalTag()); }