Skip to content

Commit 2a8609d

Browse files
author
Oleksandr Karpenko
committed
2 parents cbf4add + f115372 commit 2a8609d

File tree

5 files changed

+121
-2
lines changed

5 files changed

+121
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ define([
5252
customer = customerData.get('customer');
5353

5454
if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
55-
authenticationPopup.showModal();
55+
if (this.options.url.isRedirectRequired) {
56+
location.href = this.options.url.loginUrl;
57+
} else {
58+
authenticationPopup.showModal();
59+
}
5660

5761
return false;
5862
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ define([
3333
"url": {
3434
"checkout": window.checkout.checkoutUrl,
3535
"update": window.checkout.updateItemQtyUrl,
36-
"remove": window.checkout.removeItemUrl
36+
"remove": window.checkout.removeItemUrl,
37+
"loginUrl": window.checkout.customerLoginUrl,
38+
"isRedirectRequired": window.checkout.isRedirectRequired
3739
},
3840
"button": {
3941
"checkout": "#top-cart-btn-checkout",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Cart;
7+
8+
use Magento\Customer\Model\Checkout\ConfigProvider;
9+
10+
class ConfigPlugin
11+
{
12+
/**
13+
* @var ConfigProvider
14+
*/
15+
protected $configProvider;
16+
17+
/**
18+
* @param ConfigProvider $configProvider
19+
*/
20+
public function __construct(
21+
ConfigProvider $configProvider
22+
) {
23+
$this->configProvider = $configProvider;
24+
}
25+
26+
/**
27+
* @param \Magento\Checkout\Block\Cart\Sidebar $subject
28+
* @param array $result
29+
* @return array
30+
*
31+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
32+
*/
33+
public function afterGetConfig(\Magento\Checkout\Block\Cart\Sidebar $subject, array $result)
34+
{
35+
return array_merge_recursive($result, $this->configProvider->getConfig());
36+
}
37+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Checkout;
7+
8+
use Magento\Checkout\Model\ConfigProviderInterface;
9+
use Magento\Customer\Model\Url;
10+
use Magento\Framework\UrlInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
13+
class ConfigProvider implements ConfigProviderInterface
14+
{
15+
/**
16+
* @var StoreManagerInterface
17+
*/
18+
protected $storeManager;
19+
20+
/**
21+
* @var UrlInterface
22+
*/
23+
protected $urlBuilder;
24+
25+
/**
26+
* @param UrlInterface $urlBuilder
27+
* @param StoreManagerInterface $storeManager
28+
*/
29+
public function __construct(
30+
UrlInterface $urlBuilder,
31+
StoreManagerInterface $storeManager
32+
) {
33+
$this->urlBuilder = $urlBuilder;
34+
$this->storeManager = $storeManager;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getConfig()
41+
{
42+
return [
43+
'customerLoginUrl' => $this->getLoginUrl(),
44+
'isRedirectRequired' => $this->isRedirectRequired(),
45+
];
46+
}
47+
48+
/**
49+
* Returns URL to login controller action
50+
*
51+
* @return string
52+
*/
53+
protected function getLoginUrl()
54+
{
55+
return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN);
56+
}
57+
58+
/**
59+
* Whether redirect to login page is required
60+
*
61+
* @return bool
62+
*/
63+
protected function isRedirectRequired()
64+
{
65+
$baseUrl = $this->storeManager->getStore()->getBaseUrl();
66+
67+
if (strpos($this->getLoginUrl(), $baseUrl) !== false) {
68+
return false;
69+
}
70+
71+
return true;
72+
}
73+
}

app/code/Magento/Customer/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@
5454
<type name="Magento\Customer\Controller\AccountInterface">
5555
<plugin name="customer_account" type="Magento\Customer\Controller\Plugin\Account" />
5656
</type>
57+
<type name="Magento\Checkout\Block\Cart\Sidebar">
58+
<plugin name="customer_cart" type="\Magento\Customer\Model\Cart\ConfigPlugin" />
59+
</type>
5760
</config>

0 commit comments

Comments
 (0)