You can do this job by a Plugin
Create di.xml file with the following content:
app/code/VendorName/Module_Name/etc/frontend/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Controller\Category\View"> <plugin name="no_product_category" type="VendorName\Module_Name\Plugin\Catalog\Controller\Category\View"/> </type> </config>
2. app/code/VendorName/Module_Name/Plugin/Catalog/Controller/Category/View.php
<?php namespace VendorName\Module_Name\Plugin\Catalog\Controller\Category; class View extends \Magento\Catalog\Controller\Category\View { public function afterExecute(\Magento\Catalog\Controller\Category\View $subject, $result) { $category = $this->_coreRegistry->registry('current_category'); if(!$category->getProductCollection()->getSize()){ $result->getConfig()->setPageLayout('1column'); } return $result; } }
0 Comments