Пример #1
0
 /**
  * Renders CMS page
  *
  * @param Action $action
  * @param int $pageId
  * @param bool $renderLayout
  * @return bool
  */
 protected function _renderPage(Action $action, $pageId = null, $renderLayout = true)
 {
     if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
         $delimiterPosition = strrpos($pageId, '|');
         if ($delimiterPosition) {
             $pageId = substr($pageId, 0, $delimiterPosition);
         }
         $this->_page->setStoreId($this->_storeManager->getStore()->getId());
         if (!$this->_page->load($pageId)) {
             return false;
         }
     }
     if (!$this->_page->getId()) {
         return false;
     }
     $inRange = $this->_localeDate->isScopeDateInInterval(null, $this->_page->getCustomThemeFrom(), $this->_page->getCustomThemeTo());
     if ($this->_page->getCustomTheme()) {
         if ($inRange) {
             $this->_design->setDesignTheme($this->_page->getCustomTheme());
         }
     }
     $this->_view->getLayout()->getUpdate()->addHandle('default')->addHandle('cms_page_view');
     $this->_view->addPageLayoutHandles(array('id' => $this->_page->getIdentifier()));
     $this->_view->addActionLayoutHandles();
     if ($this->_page->getRootTemplate()) {
         if ($this->_page->getCustomRootTemplate() && $this->_page->getCustomRootTemplate() != 'empty' && $inRange) {
             $handle = $this->_page->getCustomRootTemplate();
         } else {
             $handle = $this->_page->getRootTemplate();
         }
         $this->_pageLayout->applyHandle($handle);
     }
     $this->_eventManager->dispatch('cms_page_render', array('page' => $this->_page, 'controller_action' => $action));
     $this->_view->loadLayoutUpdates();
     if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
         $layoutUpdate = $this->_page->getCustomLayoutUpdateXml();
     } else {
         $layoutUpdate = $this->_page->getLayoutUpdateXml();
     }
     if (!empty($layoutUpdate)) {
         $this->_view->getLayout()->getUpdate()->addUpdate($layoutUpdate);
     }
     $this->_view->generateLayoutXml()->generateLayoutBlocks();
     $contentHeadingBlock = $this->_view->getLayout()->getBlock('page_content_heading');
     if ($contentHeadingBlock) {
         $contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading());
         $contentHeadingBlock->setContentHeading($contentHeading);
     }
     if ($this->_page->getRootTemplate()) {
         $this->_pageLayout->applyTemplate($this->_page->getRootTemplate());
     }
     /* @TODO: Move catalog and checkout storage types to appropriate modules */
     $messageBlock = $this->_view->getLayout()->getMessagesBlock();
     $messageBlock->addStorageType($this->messageManager->getDefaultGroup());
     $messageBlock->addMessages($this->messageManager->getMessages(true));
     if ($renderLayout) {
         $this->_view->renderLayout();
     }
     return true;
 }
Пример #2
0
 /**
  * Inits layout for viewing product page
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\App\Action\Action $controller
  * @param null|\Magento\Framework\Object $params
  *
  * @return \Magento\Catalog\Helper\Product\View
  */
 public function initProductLayout($product, $controller, $params = null)
 {
     $settings = $this->_catalogDesign->getDesignSettings($product);
     if ($settings->getCustomDesign()) {
         $this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
     }
     $update = $this->_view->getLayout()->getUpdate();
     $update->addHandle('default');
     if ($params && $params->getBeforeHandles()) {
         foreach ($params->getBeforeHandles() as $handle) {
             $this->_view->addPageLayoutHandles(array('id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()), $handle);
         }
     }
     $this->_view->addPageLayoutHandles(array('id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()));
     if ($params && $params->getAfterHandles()) {
         foreach ($params->getAfterHandles() as $handle) {
             $this->_view->addPageLayoutHandles(array('id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()), $handle);
         }
     }
     $this->_view->loadLayoutUpdates();
     // Apply custom layout update once layout is loaded
     $layoutUpdates = $settings->getLayoutUpdates();
     if ($layoutUpdates) {
         if (is_array($layoutUpdates)) {
             foreach ($layoutUpdates as $layoutUpdate) {
                 $update->addUpdate($layoutUpdate);
             }
         }
     }
     $this->_view->generateLayoutXml();
     $this->_view->generateLayoutBlocks();
     // Apply custom layout (page) template once the blocks are generated
     if ($settings->getPageLayout()) {
         $this->_pageLayout->applyTemplate($settings->getPageLayout());
     }
     $currentCategory = $this->_coreRegistry->registry('current_category');
     $root = $this->_view->getLayout()->getBlock('root');
     if ($root) {
         $controllerClass = $this->_request->getFullActionName();
         if ($controllerClass != 'catalog-product-view') {
             $root->addBodyClass('catalog-product-view');
         }
         $root->addBodyClass('product-' . $product->getUrlKey());
         if ($currentCategory instanceof \Magento\Catalog\Model\Category) {
             $root->addBodyClass('categorypath-' . $currentCategory->getUrlPath())->addBodyClass('category-' . $currentCategory->getUrlKey());
         }
     }
     return $this;
 }
Пример #3
0
 public function testApplyCustomLayoutUpdate()
 {
     $categoryId = 123;
     $pageLayout = 'page_layout';
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Catalog\\Helper\\Category', $this->categoryHelper], ['Magento\\Theme\\Helper\\Layout', $this->layoutHelper]]));
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([[Action::PARAM_NAME_URL_ENCODED], ['id', false, $categoryId]]));
     $this->categoryFactory->expects($this->any())->method('create')->will($this->returnValue($this->category));
     $this->category->expects($this->any())->method('setStoreId')->will($this->returnSelf());
     $this->category->expects($this->any())->method('load')->with($categoryId)->will($this->returnSelf());
     $this->categoryHelper->expects($this->any())->method('canShow')->will($this->returnValue(true));
     $settings = $this->getMock('Magento\\Framework\\Object', ['getPageLayout'], [], '', false);
     $settings->expects($this->atLeastOnce())->method('getPageLayout')->will($this->returnValue($pageLayout));
     $this->catalogDesign->expects($this->any())->method('getDesignSettings')->will($this->returnValue($settings));
     $this->layoutHelper->expects($this->once())->method('applyHandle')->with($pageLayout);
     $this->action->execute();
 }
Пример #4
0
 /**
  * Retrieve current page layout
  *
  * @return \Magento\Framework\Object
  */
 public function getPageLayout()
 {
     return $this->_layoutHelper->getCurrentPageLayout();
 }