I want to redirect customer using controller when button is clicked in one of my phtml files.

So far I got, controller:

public function execute(){
    return $this->addToCart();

public function addToCart(){
    // some logic

The above is working fine (redirecting) when you access the controller via URL (www.mydomain.com/batchorder/index/addtocart).

And here is my .phtml file:

let controllerUrl = "<?php echo $block-getUrl('batchorder/index/addtocart'); ?>"
"products": JSON.stringify(sideCart.SideCartProducts)

The post request returns my logic as it should, however, it is not redirecting. Anyone can help?


try replace "post" to this:


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.