当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::canUseCanonicalTag方法代码示例

本文整理汇总了PHP中Magento\Catalog\Helper\Product::canUseCanonicalTag方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::canUseCanonicalTag方法的具体用法?PHP Product::canUseCanonicalTag怎么用?PHP Product::canUseCanonicalTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Helper\Product的用法示例。


在下文中一共展示了Product::canUseCanonicalTag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _prepareLayout

 /**
  * 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();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:38,代码来源:View.php

示例2: _prepareLayout

 /**
  * 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();
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:44,代码来源:View.php

示例3: testCanUseCanonicalTag

 /**
  * @magentoConfigFixture current_store catalog/seo/product_canonical_tag 1
  */
 public function testCanUseCanonicalTag()
 {
     $this->assertEquals(1, $this->_helper->canUseCanonicalTag());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:7,代码来源:ProductTest.php


注:本文中的Magento\Catalog\Helper\Product::canUseCanonicalTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。