2

In magento 2, Product detail page is coming with different layout, some product render with 1 page column while some with 2 column, i saved all product in admin for NO LAYOUT but its not working, how to resolve this. I need 1 column layout only. I am using Magento ver. 2.0.7

1

At magento, top most priority is Db values.

So, If you will saved all product in admin for 1Column then it may be work's Note: that after apply, you need to flush cache.

If it is not work then there are should be some observer which change pay layout

Solution

for this case, you can use event layout_generate_blocks_before,using this event you can change pagelayout

Observer

<?php
namespace [Vendor]\[ModuleName]\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;

class ObserverChangeLayoutForProductview implements ObserverInterface
{


    /**
     * @var \Magento\Framework\App\ActionFlag
     */
    protected $_actionFlag;

    /**
     * @var \Magento\Framework\Message\ManagerInterface
     */
    protected $messageManager;

    /**
     * @var \Magento\Framework\App\Response\RedirectInterface
     */
    protected $redirect;


    private $_pageConfig;

    /**
     * @param \Magento\Framework\App\ActionFlag $actionFlag
     * @param \Magento\Framework\Message\ManagerInterface $messageManager
     */
    public function __construct(
        \Magento\Framework\App\ActionFlag $actionFlag,
        \Magento\Framework\Message\ManagerInterface $messageManager,
    \Magento\Framework\View\Page\Config $pageConfig     
    ) {
        $this->_actionFlag = $actionFlag;
        $this->messageManager = $messageManager;
        $this->redirect = $redirect;
         $this->_pageConfig = $pageConfig; 
    }

    /**
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        /** @var \Magento\Framework\App\Action\Action $controller */
        $full_action_name = $observer->getFullActionName();

        $layout = $observer->getEvent()->getLayout();
        if($full_action_name == 'catalog_product_view'){
            //print_r($layout->getBlock('head')->getRobots());
            $this->_pageConfig->setPageLayout('1column');
        }

    }

}
0

Override catalog_product_view.xml in your module and add below code.

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 </page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.