We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Override view block using di.xml and add the below code into that file
    <preference for="MagentoCatalogBlockCategoryView" type="VendorModuleBlockCategoryView"/>

    Create the View.php file under your custom module with this path Vendor/Module/Block/Category/View.php and add the below code.

    <?php
    
    namespace VendorModuleBlockCategory;
    
    use MagentoCatalogApiProductRepositoryInterface;
    use MagentoCatalogModelCategory;
    
    class View extends MagentoCatalogBlockCategoryView
    {
        protected $_urlInterface;
    
        public function __construct(
            MagentoFrameworkViewElementTemplateContext $context,
            MagentoCatalogModelLayerResolver $layerResolver,
            MagentoFrameworkRegistry $registry,
            MagentoCatalogHelperCategory $categoryHelper,
            MagentoFrameworkUrlInterface $urlInterface,
            array $data = []
        ) {
            $this->_urlInterface = $urlInterface;
            $this->_categoryHelper = $categoryHelper;
            $this->_catalogLayer = $layerResolver->get();
            $this->_coreRegistry = $registry;
            parent::__construct($context, $layerResolver, $registry, $categoryHelper, $data);
        }
    
        protected function _prepareLayout()
        {
            parent::_prepareLayout();
    
            $this->getLayout()->createBlock(MagentoCatalogBlockBreadcrumbs::class);
    
            $category = $this->getCurrentCategory();
            if ($category) {
                $title = $category->getMetaTitle();
                if ($title) {
                    $this->pageConfig->getTitle()->set($title);
                }
                $description = $category->getMetaDescription();
                if ($description) {
                    $this->pageConfig->setDescription($description);
                }
                $keywords = $category->getMetaKeywords();
                if ($keywords) {
                    $this->pageConfig->setKeywords($keywords);
                }
                if ($this->_categoryHelper->canUseCanonicalTag()) {
                    $this->pageConfig->addRemotePageAsset(
                        $category->getUrl(),
                        'canonical',
                        ['attributes' => ['rel' => 'canonical']]
                    );
                }
    
                $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
                if ($pageMainTitle) {
                    $pageMainTitle->setPageTitle($this->getCurrentCategory()->getName());
                }
            }
    
            return $this;
        }
    }

     

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote