Пример #1
0
 /**
  * Add meta information from product to head block
  *
  * @return \Magento\Catalog\Block\Product\View
  */
 protected function _prepareLayout()
 {
     $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Breadcrumbs');
     $product = $this->getProduct();
     if (!$product) {
         return parent::_prepareLayout();
     }
     $title = $product->getMetaTitle();
     if ($title) {
         $this->pageConfig->getTitle()->set($title);
     }
     $keyword = $product->getMetaKeyword();
     $currentCategory = $this->_coreRegistry->registry('current_category');
     if ($keyword) {
         $this->pageConfig->setKeywords($keyword);
     } elseif ($currentCategory) {
         $this->pageConfig->setKeywords($product->getName());
     }
     $description = $product->getMetaDescription();
     if ($description) {
         $this->pageConfig->setDescription($description);
     } else {
         $this->pageConfig->setDescription($this->string->substr($product->getDescription(), 0, 255));
     }
     if ($this->_productHelper->canUseCanonicalTag()) {
         $this->pageConfig->addRemotePageAsset($product->getUrlModel()->getUrl($product, ['_ignore_category' => true]), 'canonical', ['attributes' => ['rel' => 'canonical']]);
     }
     $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
     if ($pageMainTitle) {
         $pageMainTitle->setPageTitle($product->getName());
     }
     return parent::_prepareLayout();
 }
Пример #2
0
 /**
  * Preparing layout
  *
  * @return \Magento\Catalog\Block\Product\Compare\ListCompare
  */
 protected function _prepareLayout()
 {
     $this->pageConfig->getTitle()->set(__('Products Comparison List') . ' - ' . $this->pageConfig->getTitle()->getDefault());
     return parent::_prepareLayout();
 }
Пример #3
0
 /**
  * Add meta information from product to head block
  *
  * @return \Magento\Catalog\Block\Product\View
  */
 protected function _prepareLayout()
 {
     $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Breadcrumbs');
     $product = $this->getProduct();
     if (!$product) {
         return parent::_prepareLayout();
     }
     $headBlock = $this->getLayout()->getBlock('head');
     if ($headBlock) {
         $title = $product->getMetaTitle();
         if ($title) {
             $headBlock->setTitle($title);
         }
         $keyword = $product->getMetaKeyword();
         $currentCategory = $this->_coreRegistry->registry('current_category');
         if ($keyword) {
             $headBlock->setKeywords($keyword);
         } elseif ($currentCategory) {
             $headBlock->setKeywords($product->getName());
         }
         $description = $product->getMetaDescription();
         if ($description) {
             $headBlock->setDescription($description);
         } else {
             $headBlock->setDescription($this->string->substr($product->getDescription(), 0, 255));
         }
         //@todo: move canonical link to separate block
         $childBlockName = 'magento-page-head-product-canonical-link';
         if ($this->_productHelper->canUseCanonicalTag() && !$headBlock->getChildBlock($childBlockName)) {
             $params = array('_ignore_category' => true);
             $headBlock->addChild($childBlockName, 'Magento\\Theme\\Block\\Html\\Head\\Link', array('url' => $product->getUrlModel()->getUrl($product, $params), 'properties' => array('attributes' => array('rel' => 'canonical'))));
         }
     }
     $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
     if ($pageMainTitle) {
         $pageMainTitle->setPageTitle($product->getName());
     }
     return parent::_prepareLayout();
 }