Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Cnc/Catalog/Observer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Catalog/Observer/LayoutLoadBefore.php
<?php
/**
 * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * <[email protected]>
 */

declare(strict_types=1);

namespace Cnc\Catalog\Observer;

use Magento\Catalog\Model\Category;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\LayoutInterface;

class LayoutLoadBefore implements ObserverInterface
{
    /**
     * @var Registry
     */
    private $registry;

    /**
     * LayoutLoadBefore constructor.
     * @param Registry $registry
     */
    public function __construct(
        Registry $registry
    ) {
        $this->registry = $registry;
    }

    /**
     * Add a custom handle to categories of page type 'PAGE' and level 2
     *
     * @param Observer $observer
     * @return LayoutLoadBefore
     */
    public function execute(Observer $observer): LayoutLoadBefore
    {
        $action = $observer->getData('full_action_name');
        if ($action != 'catalog_category_view') {
            return $this;
        }

        /** @var Category $category */
        $category = $this->registry->registry('current_category');
        if (!$category) {
            return $this;
        }

        if ((int)$category->getLevel() === 2
            && $category->getDisplayMode() === Category::DM_PAGE
        ) {
            /** @var LayoutInterface $layout */
            $layout = $observer->getData('layout');
            $layout->getUpdate()->addHandle('catalog_category_view_landing');
        }

        return $this;
    }
}

Spamworldpro Mini