Esempio n. 1
0
 /**
  * @dataProvider getThemeModel
  */
 public function testApplyCustomDesign($theme)
 {
     $this->_model->applyCustomDesign($theme);
     $design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\DesignInterface');
     $this->assertEquals('package', $design->getDesignTheme()->getPackageCode());
     $this->assertEquals('theme', $design->getDesignTheme()->getThemeCode());
 }
Esempio n. 2
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->categoryRepository->expects($this->any())->method('get')->with($categoryId)->will($this->returnValue($this->category));
     $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->action->execute();
 }
Esempio n. 3
0
 /**
  * Category view action
  *
  * @return void
  */
 public function execute()
 {
     if ($this->_request->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED)) {
         $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
         return;
     }
     $category = $this->_initCategory();
     if ($category) {
         $settings = $this->_catalogDesign->getDesignSettings($category);
         // apply custom design
         if ($settings->getCustomDesign()) {
             $this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
         }
         $this->_catalogSession->setLastViewedCategoryId($category->getId());
         $update = $this->_view->getLayout()->getUpdate();
         $update->addHandle('default');
         if ($category->getIsAnchor()) {
             $type = $category->hasChildren() ? 'layered' : 'layered_without_children';
         } else {
             $type = $category->hasChildren() ? 'default' : 'default_without_children';
         }
         if (!$category->hasChildren()) {
             // Two levels removed from parent.  Need to add default page type.
             $parentType = strtok($type, '_');
             $this->_view->addPageLayoutHandles(array('type' => $parentType));
         }
         $this->_view->addPageLayoutHandles(array('type' => $type, 'id' => $category->getId()));
         // apply custom layout (page) template once the blocks are generated
         if ($settings->getPageLayout()) {
             $this->_objectManager->get('Magento\\Theme\\Helper\\Layout')->applyHandle($settings->getPageLayout());
         }
         $this->_view->loadLayoutUpdates();
         // apply custom layout update once layout is loaded
         $layoutUpdates = $settings->getLayoutUpdates();
         if ($layoutUpdates && is_array($layoutUpdates)) {
             foreach ($layoutUpdates as $layoutUpdate) {
                 $update->addUpdate($layoutUpdate);
             }
         }
         $this->_view->generateLayoutXml();
         $this->_view->generateLayoutBlocks();
         $root = $this->_view->getLayout()->getBlock('root');
         if ($root) {
             $root->addBodyClass('categorypath-' . $category->getUrlPath())->addBodyClass('category-' . $category->getUrlKey());
         }
         $this->_view->getLayout()->initMessages();
         $this->_view->renderLayout();
     } elseif (!$this->getResponse()->isRedirect()) {
         $this->_forward('noroute');
     }
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 /**
  * Category view action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     if ($this->_request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED)) {
         return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl());
     }
     $category = $this->_initCategory();
     if ($category) {
         $this->layerResolver->create(Resolver::CATALOG_LAYER_CATEGORY);
         $settings = $this->_catalogDesign->getDesignSettings($category);
         // apply custom design
         if ($settings->getCustomDesign()) {
             $this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
         }
         $this->_catalogSession->setLastViewedCategoryId($category->getId());
         $page = $this->resultPageFactory->create();
         // apply custom layout (page) template once the blocks are generated
         if ($settings->getPageLayout()) {
             $page->getConfig()->setPageLayout($settings->getPageLayout());
         }
         $hasChildren = $category->hasChildren();
         if ($category->getIsAnchor()) {
             $type = $hasChildren ? 'layered' : 'layered_without_children';
         } else {
             $type = $hasChildren ? 'default' : 'default_without_children';
         }
         if (!$hasChildren) {
             // Two levels removed from parent.  Need to add default page type.
             $parentType = strtok($type, '_');
             $page->addPageLayoutHandles(['type' => $parentType]);
         }
         $page->addPageLayoutHandles(['type' => $type, 'id' => $category->getId()]);
         // apply custom layout update once layout is loaded
         $layoutUpdates = $settings->getLayoutUpdates();
         if ($layoutUpdates && is_array($layoutUpdates)) {
             foreach ($layoutUpdates as $layoutUpdate) {
                 $page->addUpdate($layoutUpdate);
                 $page->addPageLayoutHandles(['layout_update' => md5($layoutUpdate)]);
             }
         }
         $page->getConfig()->addBodyClass('page-products')->addBodyClass('categorypath-' . $this->categoryUrlPathGenerator->getUrlPath($category))->addBodyClass('category-' . $category->getUrlKey());
         return $page;
     } elseif (!$this->getResponse()->isRedirect()) {
         return $this->resultForwardFactory->create()->forward('noroute');
     }
 }
Esempio n. 6
0
 /**
  * Init layout for viewing product page
  *
  * @param \Magento\Framework\View\Result\Page $resultPage
  * @param \Magento\Catalog\Model\Product $product
  * @param null|\Magento\Framework\Object $params
  * @return \Magento\Catalog\Helper\Product\View
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function initProductLayout(ResultPage $resultPage, $product, $params = null)
 {
     $settings = $this->_catalogDesign->getDesignSettings($product);
     $pageConfig = $resultPage->getConfig();
     if ($settings->getCustomDesign()) {
         $this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
     }
     // Apply custom page layout
     if ($settings->getPageLayout()) {
         $pageConfig->setPageLayout($settings->getPageLayout());
     }
     $urlSafeSku = rawurlencode($product->getSku());
     // Load default page handles and page configurations
     if ($params && $params->getBeforeHandles()) {
         foreach ($params->getBeforeHandles() as $handle) {
             $resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()], $handle);
         }
     }
     $resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()]);
     if ($params && $params->getAfterHandles()) {
         foreach ($params->getAfterHandles() as $handle) {
             $resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()], $handle);
         }
     }
     // Apply custom layout update once layout is loaded
     $update = $resultPage->getLayout()->getUpdate();
     $layoutUpdates = $settings->getLayoutUpdates();
     if ($layoutUpdates) {
         if (is_array($layoutUpdates)) {
             foreach ($layoutUpdates as $layoutUpdate) {
                 $update->addUpdate($layoutUpdate);
             }
         }
     }
     $currentCategory = $this->_coreRegistry->registry('current_category');
     $controllerClass = $this->_request->getFullActionName();
     if ($controllerClass != 'catalog-product-view') {
         $pageConfig->addBodyClass('catalog-product-view');
     }
     $pageConfig->addBodyClass('product-' . $product->getUrlKey());
     if ($currentCategory instanceof \Magento\Catalog\Model\Category) {
         $pageConfig->addBodyClass('categorypath-' . $this->categoryUrlPathGenerator->getUrlPath($currentCategory))->addBodyClass('category-' . $currentCategory->getUrlKey());
     }
     return $this;
 }