Question

I need to move my category.description to the bottom of the page when in list mode, and leave it at the top when in grid mode, but who sets the position is the correct catalog_category_view? Is there any way to do this?

Était-ce utile?

La solution

You can achieve this by below code. For that you need to create one custom module.

As per your requirement , you need category.description to the bottom of the page when in list mode. So you can achieve this by creating your custom handle. Please follow below steps.

Please create files as per mentioned below in your custom module.

Step 1: Create routes.xml file under path PackageName/MoveDescription/etc/frontend/

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
        <route id="movedescription" frontName="movedescription">
            <module name="PackageName_MoveDescription" />
        </route>
    </router>
</config>

Step 2: Create Index.php file under path PackageName/MoveDescription/Controller/Index/

<?php

namespace PackageName\MoveDescription\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
    public function execute() {
        $this->_view->loadLayout();
        $this->_view->renderLayout();
    }
}

Step 3: Create movedescription_index_index.xml under path PackageName/MoveDescription/view/frontend/layout/

<?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">
    <body>
        <move element="category.description" destination="main.content" after="columns"/>
    </body>
</page>

Step 3: Create events.xml file under path PackageName/MoveDescription/etc/

<?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="load_custom_handler" instance="PackageName\MoveDescription\Observer\LayoutLoadBefore" />
    </event>
</config>

Step 4: Create LayoutLoadBefore.php file under path PackageName/MoveDescription/Observer/

<?php
namespace PackageName\MoveDescription\Observer;

class LayoutLoadBefore implements \Magento\Framework\Event\ObserverInterface 
{
    protected $request;

    public function __construct(
        \Magento\Framework\App\Request\Http $request
    ){
        $this->request = $request;
    }  

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $fullActionName = $this->request->getFullActionName();
        if($fullActionName == 'catalog_category_view')
        {
            $params = $this->request->getParams();
            if(isset($params['product_list_mode']) && $params['product_list_mode'] == 'list') {
                $layout = $observer->getEvent()->getLayout();
                $layout->getUpdate()->addHandle('movedescription_index_index');
            }
        }
        return $this;
    }
}

This code will surely work for you.

Cheers!

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top