當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AbstractProduct::_prepareLayout方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Block\Product\AbstractProduct::_prepareLayout方法的典型用法代碼示例。如果您正苦於以下問題:PHP AbstractProduct::_prepareLayout方法的具體用法?PHP AbstractProduct::_prepareLayout怎麽用?PHP AbstractProduct::_prepareLayout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Block\Product\AbstractProduct的用法示例。


在下文中一共展示了AbstractProduct::_prepareLayout方法的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

 /**
  * 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();
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:10,代碼來源:ListCompare.php

示例3: _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


注:本文中的Magento\Catalog\Block\Product\AbstractProduct::_prepareLayout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。