@@ -74,26 +74,18 @@ public function __construct(
74
74
/**
75
75
* Set back redirect url to response
76
76
*
77
+ * @param null|string $backUrl
78
+ *
77
79
* @return \Magento\Framework\Controller\Result\Redirect
78
80
*/
79
- protected function _goBack ()
81
+ protected function _goBack ($ backUrl = null )
80
82
{
81
- $ returnUrl = $ this ->getRequest ()->getParam ('return_url ' );
82
83
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
83
- if ($ returnUrl && $ this ->_isInternalUrl ($ returnUrl )) {
84
- $ this ->messageManager ->getMessages ()->clear ();
85
- $ resultRedirect ->setUrl ($ returnUrl );
86
- } elseif (!$ this ->_scopeConfig ->getValue ('checkout/cart/redirect_to_cart ' , ScopeInterface::SCOPE_STORE )
87
- && !$ this ->getRequest ()->getParam ('in_cart ' )
88
- && ($ backUrl = $ this ->_redirect ->getRefererUrl ())
89
- ) {
84
+
85
+ if ($ backUrl || $ backUrl = $ this ->getBackUrl ($ this ->_redirect ->getRefererUrl ())) {
90
86
$ resultRedirect ->setUrl ($ backUrl );
91
- } else {
92
- if ($ this ->getRequest ()->getActionName () == 'add ' && !$ this ->getRequest ()->getParam ('in_cart ' )) {
93
- $ this ->_checkoutSession ->setContinueShoppingUrl ($ this ->_redirect ->getRefererUrl ());
94
- }
95
- $ resultRedirect ->setPath ('checkout/cart ' );
96
87
}
88
+
97
89
return $ resultRedirect ;
98
90
}
99
91
@@ -118,4 +110,34 @@ protected function _isInternalUrl($url)
118
110
$ secure = strpos ($ url , $ store ->getBaseUrl (\Magento \Framework \UrlInterface::URL_TYPE_LINK , true )) === 0 ;
119
111
return $ unsecure || $ secure ;
120
112
}
113
+
114
+ /**
115
+ * Get resolved back url
116
+ *
117
+ * @param null $defaultUrl
118
+ *
119
+ * @return mixed|null|string
120
+ */
121
+ protected function getBackUrl ($ defaultUrl = null )
122
+ {
123
+ $ returnUrl = $ this ->getRequest ()->getParam ('return_url ' );
124
+ if ($ returnUrl && $ this ->_isInternalUrl ($ returnUrl )) {
125
+ $ this ->messageManager ->getMessages ()->clear ();
126
+ return $ returnUrl ;
127
+ }
128
+
129
+ $ shouldRedirectToCart = $ this ->_scopeConfig ->getValue (
130
+ 'checkout/cart/redirect_to_cart ' ,
131
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE
132
+ );
133
+
134
+ if ($ shouldRedirectToCart || $ this ->getRequest ()->getParam ('in_cart ' )) {
135
+ if ($ this ->getRequest ()->getActionName () == 'add ' && !$ this ->getRequest ()->getParam ('in_cart ' )) {
136
+ $ this ->_checkoutSession ->setContinueShoppingUrl ($ this ->_redirect ->getRefererUrl ());
137
+ }
138
+ return $ this ->_url ->getUrl ('checkout/cart ' );
139
+ }
140
+
141
+ return $ defaultUrl ;
142
+ }
121
143
}
0 commit comments