Create Module OnePageProduct
Step 1: Create a new module named Magepow_OnePageProducts
Create the file named registration.php in the path app/code/Magento/OnePageProducts
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magento_OnePageProducts',
__DIR__
);
Create the file named module.xml in the path
app/code/Magento/OnePageProducts/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_OnePageProducts" setup_version="2.0.0" />
</config>
Create the file named routes.xml in the path
app/code/Magento/OnePageProducts/etc/frontend/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<!--Define a custom route with id and frontName-->
<route frontName="magento" id="magento">
<module name="Magento_OnePageProducts"/>
</route>
</router>
</config>
Create the Onepage.php file in the path
app/code/Magento/OnePageProducts/Controller/Product/Onepage.php
<?php
namespace Magento\OnePageProducts\Controller\Product;
class Onepage extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Catalog\Api\CategoryRepositoryInterface
*/
protected $categoryRepository;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry;
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->_coreRegistry = $coreRegistry;
$this->categoryRepository = $categoryRepository;
$this->_storeManager = $storeManager;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* @return \Magento\Framework\View\Result\Page
*/
public function execute()
{
$store = $this->_storeManager->getStore();
$category = $this->categoryRepository->get(
$store->getRootCategoryId()
);
$this->_coreRegistry->register('current_category', $category);
$page = $this->resultPageFactory->create();
$page->getLayout()->getBlock('page.main.title')->setPageTitle(__('One Page Products'));
$page->getLayout()->getBlock('breadcrumbs')->addCrumb(
'home',
[
'label' => __('Home'),
'title' => __('Go to Home Page'),
'link' => $store->getBaseUrl()
]
)->addCrumb(
'product-tag',
[
'label' => __('One Page Products'),
'title' => __('One Page Products')
]
);
$page->getConfig()->addBodyClass('page-products');
$page->getConfig()->getTitle()->set(__('One Page Products'));
$page->getConfig()->setDescription(__('One Page Products'));
$page->getConfig()->setKeywords(__('One Page Products'));
$page->getConfig()->addRemotePageAsset($this->_url->getUrl('magento/product/onepage'), 'canonical', ['attributes' => ['rel' => 'canonical']]);
return $page;
}
}
Create the layout named magento_product_onepage.xml
app/code/Magento/OnePageProducts/view/frontend/layout/magento_product_onepage.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="catalog_category_view" />
<update handle="catalog_category_view_type_layered" />
</page>
Run the below commands and check.
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush