diff --git a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js index 052e79cbc7fced3a29f041489cd076f1a421e3b0..3882419363315a6bbfdc57eb8a304c060ef7e143 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js @@ -52,7 +52,11 @@ define([ customer = customerData.get('customer'); if (!customer().firstname && !cart().isGuestCheckoutAllowed) { - authenticationPopup.showModal(); + if (this.options.url.isRedirectRequired) { + location.href = this.options.url.loginUrl; + } else { + authenticationPopup.showModal(); + } return false; } diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js b/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js index 68f02b5d5722412fa17880c59124cf5ee84cdb03..2a9375a40eba1f95c258bc2cebc42b7d021d5615 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js @@ -33,7 +33,9 @@ define([ "url": { "checkout": window.checkout.checkoutUrl, "update": window.checkout.updateItemQtyUrl, - "remove": window.checkout.removeItemUrl + "remove": window.checkout.removeItemUrl, + "loginUrl": window.checkout.customerLoginUrl, + "isRedirectRequired": window.checkout.isRedirectRequired }, "button": { "checkout": "#top-cart-btn-checkout", diff --git a/app/code/Magento/Customer/Model/Cart/ConfigPlugin.php b/app/code/Magento/Customer/Model/Cart/ConfigPlugin.php new file mode 100644 index 0000000000000000000000000000000000000000..2be36da4d90404f302e1a6cbba48386ad1f995ef --- /dev/null +++ b/app/code/Magento/Customer/Model/Cart/ConfigPlugin.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Customer\Model\Cart; + +use Magento\Customer\Model\Checkout\ConfigProvider; + +class ConfigPlugin +{ + /** + * @var ConfigProvider + */ + protected $configProvider; + + /** + * @param ConfigProvider $configProvider + */ + public function __construct( + ConfigProvider $configProvider + ) { + $this->configProvider = $configProvider; + } + + /** + * @param \Magento\Checkout\Block\Cart\Sidebar $subject + * @param array $result + * @return array + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterGetConfig(\Magento\Checkout\Block\Cart\Sidebar $subject, array $result) + { + return array_merge_recursive($result, $this->configProvider->getConfig()); + } +} diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..f09e2129c36d1555411e702d451df283f1b31ca2 --- /dev/null +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Customer\Model\Checkout; + +use Magento\Checkout\Model\ConfigProviderInterface; +use Magento\Customer\Model\Url; +use Magento\Framework\UrlInterface; +use Magento\Store\Model\StoreManagerInterface; + +class ConfigProvider implements ConfigProviderInterface +{ + /** + * @var StoreManagerInterface + */ + protected $storeManager; + + /** + * @var UrlInterface + */ + protected $urlBuilder; + + /** + * @param UrlInterface $urlBuilder + * @param StoreManagerInterface $storeManager + */ + public function __construct( + UrlInterface $urlBuilder, + StoreManagerInterface $storeManager + ) { + $this->urlBuilder = $urlBuilder; + $this->storeManager = $storeManager; + } + + /** + * {@inheritdoc} + */ + public function getConfig() + { + return [ + 'customerLoginUrl' => $this->getLoginUrl(), + 'isRedirectRequired' => $this->isRedirectRequired(), + ]; + } + + /** + * Returns URL to login controller action + * + * @return string + */ + protected function getLoginUrl() + { + return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN); + } + + /** + * Whether redirect to login page is required + * + * @return bool + */ + protected function isRedirectRequired() + { + $baseUrl = $this->storeManager->getStore()->getBaseUrl(); + + if (strpos($this->getLoginUrl(), $baseUrl) !== false) { + return false; + } + + return true; + } +} diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index ad1f406500e98edf92f80ea8a3edd7a2a24f968f..0205fbf62fc367b690edeee8f98fa32b3c0f0118 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -54,4 +54,7 @@ <type name="Magento\Customer\Controller\AccountInterface"> <plugin name="customer_account" type="Magento\Customer\Controller\Plugin\Account" /> </type> + <type name="Magento\Checkout\Block\Cart\Sidebar"> + <plugin name="customer_cart" type="\Magento\Customer\Model\Cart\ConfigPlugin" /> + </type> </config>