0

How to hide the category block in navigation on all pages if the user is not a login? enter image description here

Also, if a user tries to navigate to a category via a link, it should be redirected to the login page.

  • do you want to hide category from header menu ?? – Hiren Feb 5 at 11:24
  • @Hiren Yes, and restrict access to them if the transition is through a direct link. If the transition is redirected to the login page – ann karsksya Feb 5 at 12:04
  • You can do this by event observer. – Dhiren Vasoya Feb 5 at 14:20
0

To redirect not login customer when category page is load either by URL, you can do this one.

  1. create events.xml file at the following location.

app\code\Vendor\Exxtension\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="catalog_controller_category_init_after">
        <observer name="restrict_category_load" instance="Vendor\Extension\Observer\CategoryRestrictObserver" />
    </event>
</config>
  1. Now create CategoryRestrictObserver.php file at the following location.

app\code\Vendor\Exxtension\Observer\CategoryRestrictObserver.php

<?php

namespace Vendor\Extension\Observer;

class CategoryRestrictObserver implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        // Check If customer is not login, then redirect on login page
    }
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.