0

I am currently trying to stop redirecting to product view page if someone forgets to select configure option and click on 'add to cart', instead of that it will just send popup message or alert.

Here is the Controller:

File Name: Add.php

File Path:

Magento\Checkout\Controller\Cart\Add

protected function goBack($backUrl = null, $product = null)
{ 
 $result = [];
 if ($backUrl || $backUrl = $this->getBackUrl()) {
 $backUrlas = "test";
 $result['backUrl'] = $backUrlas;
 } else {
 //some code
 }
 $this->getResponse()->representJson(
 $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result)
 );
}

as you can see if I pass value "test" it will redirect to ../test instead of that ../product.

I am not good in json, any help would be appreciated!

asked Dec 17, 2019 at 6:12

1 Answer 1

0

Add like below and check

protected function goBack($backUrl = null, $product = null)
{ 
 $result = [];
 if ($backUrl || $backUrl = $this->getBackUrl()) {
 $result['backUrlas'] = "Test";
 $result['backUrl'] = $backUrl;
 } else {
 //some code
 }
 $this->getResponse()->representJson(
 $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result)
 );
}
answered Dec 17, 2019 at 7:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.