Trying to create a module that redirects the customer to the account creation page when they add to cart if they are not logged in, I have the following code in app/code/Mason/CheckoutRedirect/Plugin/Checkout/Controller/Cart/Add.php:

namespace Mason\CheckoutRedirect\Plugin\Checkout\Controller\Cart;

class Add
     * @var \Magento\Framework\ObjectManagerInterface
    protected $objectManager;

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

     * @var \Magento\Framework\UrlInterface
    protected $url;

     * Data constructor.
     * @param \Magento\Framework\ObjectManagerInterface $objectManager
     * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
     * @param \Magento\Framework\UrlInterface $url
    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
        \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory,
        \Magento\Framework\UrlInterface $url
    ) {
        $this->objectManager = $objectManager;
        $this->resultRedirectFactory = $resultRedirectFactory;
        $this->url = $url;

    public function aroundExecute(
        \Magento\Checkout\Controller\Cart\Add $subject,
        \Closure $proceed
    ) {
        $contactUrl = $this->url->getUrl('customer/account/create');
        $result = [];
        $result['backUrl'] = $contactUrl;


All this is doing is returning a JSON object:


But it isn't redirecting

  • did you override the controller? Commented Dec 5, 2016 at 6:54

1 Answer 1


Yes, it's getting the plugin correctly, but it only returns the JSON object, rather than doing the redirect that I want it to do

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.