0

I have a site with 2 store views.

One of the views (lets call it store view X), should be accessible to only certain users, and parts of the store should be restricted when this store view is enabled.

For example, when a logged in user is of the correct customer group and X is enabled, i don't want them to access /wishlist, or customer/account, i want those pages to be redirected to the homepage.

What i've tried is to add redirects specific to store view X of type 302,

i.e. request path - wishlist, target path - ../, type 302

I've then tried reindexing and navigating to the page wishlist, only to find the redirect doesn't work. That route doesn't even hit Magento\UrlRewrite\Controller\Router match() ln 60.

how can i redirect pages such as this for a specific store view, and can someone explain why the Router isn't being hit?

Thanks,

Sophie

8
  • Link to github ticket github.com/magento/magento2/issues/8718#issuecomment-283126284 Commented Mar 1, 2017 at 9:50
  • Do you have fullpage cache enabled ? Commented Mar 1, 2017 at 12:13
  • I've tried with the cache enabled and disabled. The redirect works on some pages but not others so i'm not sure the cache is the issue. Commented Mar 1, 2017 at 12:30
  • I'm starting to think it's the Magento\Framework\App\FrontController.php dispatch() matching a custom router before the url redirect router as it loops through the router list. How do I get it to match against the url redirect router before all others though? Commented Mar 1, 2017 at 12:33
  • Indeed the router is sorted : Base Router → CMS Router → UrlRewrite Router → Default Router Commented Mar 1, 2017 at 13:56

1 Answer 1

0

You can add an observer to the controller_action_predispatch event in order to add your own logic of restriction.

events.xml

<event name="controller_action_predispatch">
    <observer name="custom_restrict" instance="Vendor\Restriction\Observer\CustomRestrict" />
</event>

CustomRestrict.php

/**
 * Implement some restriction
 *
 * @param \Magento\Framework\Event\Observer $observer
 * @return void
 */
public function execute(\Magento\Framework\Event\Observer $observer)
{
    /* @var $controller \Magento\Framework\App\Action\Action */
    $controller = $observer->getEvent()->getControllerAction();

    $this->restrictor->restrict(
        $observer->getEvent()->getRequest(),
        $this->response,
    );
}

Where $this->restrictor is your restriction class model with your logic.

But you may encounter problems if you use Varnish or other cache system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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