I have the following plugin:

namespace Company\Module\Plugin;

class DisableLoginCheckout
     * @var \Magento\Customer\Model\Session
    protected $customerSession;

     * @var \Magento\Customer\Model\Group
    protected $customerGroupCollection;

     * @var \Magento\Framework\Controller\Result\RedirectFactory
    protected $redirectFactory;

     * @var \Magento\Framework\App\Response\RedirectInterface
    protected $redirectInterface;

     * @var \Magento\Framework\Message\ManagerInterface
    protected $messageManager;

     * @var \Psr\Log\LoggerInterface
    protected $logger;

    public function __construct(
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Customer\Model\Group $customerGroupCollection,
        \Magento\Framework\Controller\Result\RedirectFactory $redirectFactory,
        \Magento\Framework\App\Response\RedirectInterface $redirectInterface,
        \Magento\Framework\Message\ManagerInterface $messageManager,
        \Psr\Log\LoggerInterface $logger
    ) {
        $this->_customerSession = $customerSession;
        $this->_customerGroupCollection = $customerGroupCollection;
        $this->resultRedirectFactory = $redirectFactory;
        $this->redirect = $redirectInterface;
        $this->messageManager = $messageManager;
        $this->_logger = $logger;

    public function beforeDispatch(
        \Magento\Checkout\Controller\Onepage $subject,
        \Magento\Framework\App\RequestInterface $request
        if ($this->getCustomerGroup() == 'Disabilitato') {

            $lastCustomerId = $this->_customerSession->getCustomerId();

            //$this->messageManager->addNoticeMessage(__('Your account has not been enabled yet'));

            /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
            $resultRedirect = $this->resultRedirectFactory->create();
            $resultRedirect->setPath('accuontdisabled', ['_secure' => true]);
            $result = $resultRedirect;

            return $result;

    public function getCustomerGroup()
            $currentGroupId = $this->_customerSession->getCustomer()->getGroupId();
            $collection = $this->_customerGroupCollection->load($currentGroupId);

            return  $collection->getCustomerGroupCode();


when I try to login with authentication-popup i've got this error

Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Store\App\Action\Plugin\StoreCheck::beforeDispatch() must implement interface Magento\Framework\App\RequestInterface, instance of Magento\Store\App\Response\Redirect given

Any help?



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Controller\Onepage">
        <plugin name="MyPlugin" type="Company\Module\Plugin\DisableLoginCheckout" />


before plugin cannot be used in this way, after plugin solves.

  • Please update your di.xml also.. Apr 15, 2018 at 5:31
  • @ToanNguyen check edit in question, please
    – krybbio
    Apr 15, 2018 at 5:50
  • Please answer your question and mark the answer as accepted if you have found the answer Apr 15, 2018 at 13:22

2 Answers 2


Your plugin implementation is fine. However, the return value is a controller of type redirect.

Subsequently, when the dispatch function kicks in after your plugin, it receives a redirect object and that's why you have this error.

Instead, I would try an around plugin myself so that you can keep a similar implementation but with the idea not to break the dispatch function anymore.

  • For my need after plugin was enough. But if you need to modify input parameters then around plugin is the best way.
    – krybbio
    Apr 16, 2018 at 14:15

before plugin cannot be used in this way, after plugin solves.

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.