This is how my add to cart functionality works :

I have a quick link for each products on home page. When I click on the link, I get a popup by ajax with add to cart functionality.

On submit, it adds product to cart and redirects to the ajax url through which the popup was generated which is wrong. Basically the popup is on home page and I want it to redirect to home page.

Now the problem is that Checkout module takes referral url which is ajax url and redirects to it.

The Cart controller has all the functions as protected so I am not even able to use interceptors.

So basically I could not find a way to do this.

1 Answer 1


There's a method called getBackUrl in Magento\Checkout\Controller\Cart that checks for return_url parameter. You could try adding a hidden input to your form with the name return_url and value of the homepage url.

If that doesn't work, you'll need to create a custom controller that extends Cart\Add and modify the execute method so that it redirects to the homepage. Then change the action of your form from checkout/cart/add to your/controller.


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.