I followed this post. However, I am getting a white screen on the Tier 3 category pages.
Troubleshooting steps:
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
I have attached my code, but removed the Client's namespace and replaced it with VendorName due NDA.
If anyone is able to advise to the possible cause, I would really appreciate it.
app/code/VendorName/CategoryPages/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'VendorName_CategoryPages',
__DIR__
); ?>
app/code/VendorName/CategoryPages/etc/config.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> <default> <categorypages> <general> <enable_frontend>1</enable_frontend> </general> </categorypages> </default> </config>
app/code/VendorName/CategoryPages/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="VendorName_CategoryPages" setup_version="1.0.0"> </module> </config>
app/code/VendorName/CategoryPages/etc/frontend/events.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="layout_load_before"> <observer name="vendorname_categorypages_layout_load_before" instance="VendorName\CategoryPages\Observer\CategoryDepthLayout" /> </event> </config>
app/code/VendorName/CategoryPages/Observer
<?php namespace VendorName\CategoryPages\Observer; use Magento\Framework\Registry; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Event\Observer; class CategoryDepthLayout implements ObserverInterface { const ACTION_NAME = 'catalog_category_view'; /** @var Registry */ private $registry; public function __construct( Registry $registry ) { $this->registry = $registry; } public function execute(Observer $observer) { if ($observer->getFullActionName() !== self::ACTION_NAME) { return; } $category = $this->registry->registry('current_category'); /** @var \Magento\Framework\View\Layout $layout */ $layout = $observer->getLayout(); $layout->getUpdate()->addHandle(self::ACTION_NAME . '_level_' . $category->getLevel()); } }
app/code/VendorName/CategoryPages/view/frontend/layout/catalog_category_view_level_3.xml
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1columns" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="columns.top"> <container name="category.view.container" htmlTag="div" htmlClass="category-view" after="-"> <block class="Magento\Catalog\Block\Category\View" template="VendorName_CategoryPages::level3.phtml"/> </container> </referenceContainer> </body> </page>
app/code/VendorName/CategoryPages/view/frontend/templates/level3.phtml
<?php if (!$block->isContentMode() || $block->isMixedMode()): ?> <?= $block->getProductListHtml() ?> <?php endif; ?> <?php $category = $block->getCurrentCategory(); $subcategories = $category->getChildrenCategories(); $_helper = $this->helper('Magento\Catalog\Helper\Output'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); if (count($subcategories) > 0) { $subcategoryList = array(); foreach($subcategories as $subcategory) { $subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($subcategory->getId()); $elements = array( 'name' => $subcategory->getName(), 'description' => $subcategory->getDescription(), 'url' => $subcategory->getUrl(), 'image' => $subcategory->getImageUrl(), 'is_sale' => $subcategory->getIsSale(), 'is_active' => $subcategory->getIsActive() ); array_push($subcategoryList, $elements); } } $featuredCategoryList = $subcategoryList; $subcategoryListKeys = array_column($subcategoryList, 'name'); $subcategoryListResult = array_multisort($subcategoryListKeys, SORT_ASC, $subcategoryList); ?> <div class="container m4-parentcategory"> <div class="row"> <div class="col-12 col-md-8 col-md-offset-2 m4-categorydetails"> <?php if ($category->getName() != '') { ?> <h2><?php echo $category->getName(); ?></h2> <?php } ?> <?php if ($category->getDescription() !== '') { ?> <?php echo $category->getDescription(); ?> <?php } ?> </div> </div> </div> <?php if (count($subcategories) > 0) { ?> <div class="m4-featuredcategories" style="background-color: #efefef;"> <div class="container"> <div class="row"> <div class="col-12"> <h2>Featured Product Classes</h2> </div> </div> <div class="row"> <div class="col-12"> <?php foreach($subcategoryList as $data) { ?> <?php if ($data['is_sale']) { ?> <div class="m4-categorycard-container col-12 col-sm-6 col-md-4 col-lg-3"> <div class="m4-categorycard" style="border: 1px solid #666;"> <div class=""> <a href="<?php echo $data['url']; ?>"> <img src="<?php echo $data['image']; ?>" /> </a> </div> <div style="padding: 10px;"> <div style="text-align: center;"> <a style="font-size: 14px; font-weight: bold !important;" href="<?php echo $data['url']; ?>"><?php echo $data['name']; ?></a> </div> <div> <?php echo $data['description']; ?> </div> <div style="text-align: center;"> <a class="btn btn-primary" href="<?php echo $data['url']; ?>">Enquire</a> </div> </div> </div> </div> <?php } ?> <?php } ?> </div> </div> </div> </div> <?php } ?> <div class="container m4-categories"> <?php if (count($subcategories) > 0): ?> <div class="row"> <div class="col-12"> <h2>Product Classes</h2> </div> </div> <div class="row"> <div class="col-12"> <?php foreach($subcategoryList as $data) { ?> <div class="m4-categorycard-container col-12 col-sm-6 col-md-4 col-lg-3"> <div class="m4-categorycard" style="border: 1px solid #666;"> <div class=""> <a href="<?php echo $data['url']; ?>"> <img src="<?php echo $data['image']; ?>" /> </a> </div> <div style="padding: 10px;"> <div style="text-align: center;"> <a style="font-size: 14px; font-weight: bold !important;" href="<?php echo $data['url']; ?>"><?php echo $data['name']; ?></a> </div> <div> <?php echo $data['description']; ?> </div> <div style="text-align: center;"> <a class="btn btn-primary" href="<?php echo $data['url']; ?>">Enquire</a> </div> </div> </div> </div> <?php } ?> </div> </div> <!-- <div class="row"> <div class="col-12"> <div class="load-more-button text-center"> <button class="btn btn-light" style="background-color: #666666; color: #ffffff;">Load More</button> </div> </div> </div> --> <?php else: ?> <?php if (!$block->isContentMode() || $block->isMixedMode()): ?> <?= $block->getProductListHtml() ?> <?php endif; ?> <?php endif; ?> </div>