Skip to content

Commit 5f8e97e

Browse files
Merge pull request #346 from magento-folks/2.0.11_bugs_pr
Fixed issues: - MAGETWO-57338: [Backport] - Customer is not redirected to checkout on login if guest is disabled - for 2.0 - MAGETWO-57513: [Backport] - Giftcard Purchase - Order Status - Processing - for 2.0 - MAGETWO-57844: [Backport] - [Github # 6294] Coupon code override cart rules with no coupon code - for 2.0
2 parents 2de4597 + 251eda1 commit 5f8e97e

File tree

12 files changed

+368
-39
lines changed

12 files changed

+368
-39
lines changed

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ define([
5555
customer = customerData.get('customer');
5656

5757
if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
58+
// set URL for redirect on successful login/registration. It's postprocessed on backend.
59+
$.cookie('login_redirect', this.options.url.checkout);
5860
if (this.options.url.isRedirectRequired) {
5961
location.href = this.options.url.loginUrl;
6062
} else {

app/code/Magento/Customer/Controller/Account/CreatePost.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
32+
* @SuppressWarnings(PHPMD.TooManyFields)
3233
*/
3334
class CreatePost extends \Magento\Customer\Controller\AbstractAccount
3435
{
@@ -81,6 +82,11 @@ class CreatePost extends \Magento\Customer\Controller\AbstractAccount
8182
*/
8283
private $accountRedirect;
8384

85+
/**
86+
* @var ScopeConfigInterface
87+
*/
88+
private $scopeConfig;
89+
8490
/**
8591
* @param Context $context
8692
* @param Session $customerSession
@@ -198,6 +204,7 @@ protected function extractAddress()
198204
*
199205
* @return void
200206
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
207+
* @SuppressWarnings(PHPMD.NPathComplexity)
201208
*/
202209
public function execute()
203210
{
@@ -257,6 +264,12 @@ public function execute()
257264
} else {
258265
$this->session->setCustomerDataAsLoggedIn($customer);
259266
$this->messageManager->addSuccess($this->getSuccessMessage());
267+
$requestedRedirect = $this->accountRedirect->getRedirectCookie();
268+
if (!$this->scopeConfig->getValue('customer/startup/redirect_dashboard') && $requestedRedirect) {
269+
$resultRedirect->setUrl($this->_redirect->success($requestedRedirect));
270+
$this->accountRedirect->clearRedirectCookie();
271+
return $resultRedirect;
272+
}
260273
$resultRedirect = $this->accountRedirect->getRedirect();
261274
}
262275
return $resultRedirect;

app/code/Magento/Customer/Controller/Account/LoginPost.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Exception\EmailNotConfirmedException;
1414
use Magento\Framework\Exception\AuthenticationException;
1515
use Magento\Framework\Data\Form\FormKey\Validator;
16+
use Magento\Framework\App\Config\ScopeConfigInterface;
1617

1718
/**
1819
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -35,6 +36,11 @@ class LoginPost extends \Magento\Customer\Controller\AbstractAccount
3536
*/
3637
protected $session;
3738

39+
/**
40+
* @var ScopeConfigInterface
41+
*/
42+
private $scopeConfig;
43+
3844
/**
3945
* @param Context $context
4046
* @param Session $customerSession
@@ -59,6 +65,35 @@ public function __construct(
5965
parent::__construct($context);
6066
}
6167

68+
/**
69+
* Set scope config
70+
*
71+
* @param ScopeConfigInterface $scopeConfig
72+
* @return void
73+
* @deprecated
74+
*/
75+
public function setScopeConfig(ScopeConfigInterface $scopeConfig)
76+
{
77+
$this->scopeConfig = $scopeConfig;
78+
}
79+
80+
/**
81+
* Get scope config
82+
*
83+
* @return ScopeConfigInterface
84+
* @deprecated
85+
*/
86+
private function getScopeConfig()
87+
{
88+
if (!($this->scopeConfig instanceof \Magento\Framework\App\Config\ScopeConfigInterface)) {
89+
return \Magento\Framework\App\ObjectManager::getInstance()->get(
90+
'Magento\Framework\App\Config\ScopeConfigInterface'
91+
);
92+
} else {
93+
return $this->scopeConfig;
94+
}
95+
}
96+
6297
/**
6398
* Login post action
6499
*
@@ -81,6 +116,14 @@ public function execute()
81116
$customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
82117
$this->session->setCustomerDataAsLoggedIn($customer);
83118
$this->session->regenerateId();
119+
$redirectUrl = $this->accountRedirect->getRedirectCookie();
120+
if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectUrl) {
121+
$this->accountRedirect->clearRedirectCookie();
122+
$resultRedirect = $this->resultRedirectFactory->create();
123+
// URL is checked to be internal in $this->_redirect->success()
124+
$resultRedirect->setUrl($this->_redirect->success($redirectUrl));
125+
return $resultRedirect;
126+
}
84127
} catch (EmailNotConfirmedException $e) {
85128
$value = $this->customerUrl->getEmailConfirmationUrl($login['username']);
86129
$message = __(

app/code/Magento/Customer/Controller/Ajax/Login.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
use Magento\Customer\Api\AccountManagementInterface;
1010
use Magento\Framework\Exception\EmailNotConfirmedException;
1111
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Customer\Model\Account\Redirect as AccountRedirect;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
1215

1316
/**
1417
* Login controller
1518
*
1619
* @method \Magento\Framework\App\RequestInterface getRequest()
1720
* @method \Magento\Framework\App\Response\Http getResponse()
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1822
*/
1923
class Login extends \Magento\Framework\App\Action\Action
2024
{
@@ -43,6 +47,18 @@ class Login extends \Magento\Framework\App\Action\Action
4347
*/
4448
protected $resultRawFactory;
4549

50+
/**
51+
* @var AccountRedirect
52+
* @deprecated
53+
*/
54+
private $accountRedirect;
55+
56+
/**
57+
* @var ScopeConfigInterface
58+
* @deprecated
59+
*/
60+
private $scopeConfig;
61+
4662
/**
4763
* Initialize Login controller
4864
*
@@ -69,12 +85,62 @@ public function __construct(
6985
$this->resultRawFactory = $resultRawFactory;
7086
}
7187

88+
/**
89+
* Get account redirect.
90+
* For release backward compatibility.
91+
*
92+
* @deprecated
93+
* @return AccountRedirect
94+
*/
95+
private function getAccountRedirect()
96+
{
97+
if (!is_object($this->accountRedirect)) {
98+
$this->accountRedirect = ObjectManager::getInstance()->get(AccountRedirect::class);
99+
}
100+
return $this->accountRedirect;
101+
}
102+
103+
/**
104+
* Account redirect setter for unit tests.
105+
*
106+
* @deprecated
107+
* @param AccountRedirect $value
108+
* @return void
109+
*/
110+
public function setAccountRedirect($value)
111+
{
112+
$this->accountRedirect = $value;
113+
}
114+
115+
/**
116+
* @deprecated
117+
* @return ScopeConfigInterface
118+
*/
119+
private function getScopeConfig()
120+
{
121+
if (!is_object($this->scopeConfig)) {
122+
$this->scopeConfig = ObjectManager::getInstance()->get(ScopeConfigInterface::class);
123+
}
124+
return $this->scopeConfig;
125+
}
126+
127+
/**
128+
* @deprecated
129+
* @param ScopeConfigInterface $value
130+
* @return void
131+
*/
132+
public function setScopeConfig($value)
133+
{
134+
$this->scopeConfig = $value;
135+
}
136+
72137
/**
73138
* Login registered users and initiate a session.
74139
*
75140
* Expects a POST. ex for JSON {"username":"[email protected]", "password":"userpassword"}
76141
*
77142
* @return \Magento\Framework\Controller\ResultInterface
143+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
78144
*/
79145
public function execute()
80146
{
@@ -103,6 +169,11 @@ public function execute()
103169
);
104170
$this->customerSession->setCustomerDataAsLoggedIn($customer);
105171
$this->customerSession->regenerateId();
172+
$redirectRoute = $this->getAccountRedirect()->getRedirectCookie();
173+
if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectRoute) {
174+
$response['redirectUrl'] = $this->_redirect->success($redirectRoute);
175+
$this->getAccountRedirect()->clearRedirectCookie();
176+
}
106177
} catch (EmailNotConfirmedException $e) {
107178
$response = [
108179
'errors' => true,

app/code/Magento/Customer/Model/Account/Redirect.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
1616
use Magento\Framework\Controller\Result\RedirectFactory;
1717
use Magento\Framework\Url\DecoderInterface;
18+
use Magento\Framework\App\ObjectManager;
19+
use Magento\Framework\Stdlib\CookieManagerInterface;
1820

1921
/**
2022
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2123
*/
2224
class Redirect
2325
{
26+
/** URL to redirect user on successful login or registration */
27+
const LOGIN_REDIRECT_URL = 'login_redirect';
28+
2429
/**
2530
* @var RequestInterface
2631
*/
@@ -56,6 +61,12 @@ class Redirect
5661
*/
5762
protected $resultRedirectFactory;
5863

64+
/**
65+
* @var CookieManagerInterface
66+
* @deprecated
67+
*/
68+
private $cookieManager;
69+
5970
/**
6071
* @param RequestInterface $request
6172
* @param Session $customerSession
@@ -196,4 +207,61 @@ private function applyRedirect($url)
196207
{
197208
$this->session->setBeforeAuthUrl($url);
198209
}
210+
211+
/**
212+
* Get Cookie manager. For release backward compatibility.
213+
*
214+
* @deprecated
215+
* @return CookieManagerInterface
216+
*/
217+
private function getCookieManager()
218+
{
219+
if (!is_object($this->cookieManager)) {
220+
$this->cookieManager = ObjectManager::getInstance()->get(CookieManagerInterface::class);
221+
}
222+
return $this->cookieManager;
223+
}
224+
225+
/**
226+
* Set cookie manager. For unit tests.
227+
*
228+
* @deprecated
229+
* @param object $value
230+
* @return void
231+
*/
232+
public function setCookieManager($value)
233+
{
234+
$this->cookieManager = $value;
235+
}
236+
237+
/**
238+
* Get redirect route from cookie for case of successful login/registration
239+
*
240+
* @return null|string
241+
*/
242+
public function getRedirectCookie()
243+
{
244+
return $this->getCookieManager()->getCookie(self::LOGIN_REDIRECT_URL, null);
245+
}
246+
247+
/**
248+
* Save redirect route to cookie for case of successful login/registration
249+
*
250+
* @param string $route
251+
* @return void
252+
*/
253+
public function setRedirectCookie($route)
254+
{
255+
$this->getCookieManager()->setPublicCookie(self::LOGIN_REDIRECT_URL, $route);
256+
}
257+
258+
/**
259+
* Clear cookie with requested route
260+
*
261+
* @return void
262+
*/
263+
public function clearRedirectCookie()
264+
{
265+
$this->getCookieManager()->deleteCookie(self::LOGIN_REDIRECT_URL);
266+
}
199267
}

0 commit comments

Comments
 (0)