/** * Set back redirect url to response * * @return $this */ protected function _goBack() { $returnUrl = $this->getRequest()->getParam('return_url'); if ($returnUrl && $this->_isInternalUrl($returnUrl)) { $this->messageManager->getMessages()->clear(); $this->getResponse()->setRedirect($returnUrl); } elseif (!$this->_scopeConfig->getValue('checkout/cart/redirect_to_cart', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) && !$this->getRequest()->getParam('in_cart') && ($backUrl = $this->_redirect->getRefererUrl())) { $this->getResponse()->setRedirect($backUrl); } else { if ($this->getRequest()->getActionName() == 'add' && !$this->getRequest()->getParam('in_cart')) { $this->_checkoutSession->setContinueShoppingUrl($this->_redirect->getRefererUrl()); } $this->_redirect('checkout/cart'); } return $this; }
/** * Get resolved back url * * @param null $defaultUrl * * @return mixed|null|string */ protected function getBackUrl($defaultUrl = null) { $returnUrl = $this->getRequest()->getParam('return_url'); if ($returnUrl && $this->_isInternalUrl($returnUrl)) { $this->messageManager->getMessages()->clear(); return $returnUrl; } $shouldRedirectToCart = $this->_scopeConfig->getValue('checkout/cart/redirect_to_cart', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($shouldRedirectToCart || $this->getRequest()->getParam('in_cart')) { if ($this->getRequest()->getActionName() == 'add' && !$this->getRequest()->getParam('in_cart')) { $this->_checkoutSession->setContinueShoppingUrl($this->_redirect->getRefererUrl()); } return $this->_url->getUrl('checkout/cart'); } return $defaultUrl; }