From 685c343e8e092fda6858296e46bd059d67cba8cc Mon Sep 17 00:00:00 2001
From: Stanislav Idolov <sidolov@ebay.com>
Date: Fri, 26 Jun 2015 16:21:17 +0300
Subject: [PATCH] MAGETWO-38660: Provide ability to log-in during checkout --
 fixes after CR

---
 .../Magento/Checkout/Block/Cart/Sidebar.php   | 10 +++++++
 .../frontend/templates/cart/minicart.phtml    | 13 ++++-----
 .../frontend/templates/onepage/link.phtml     | 24 +----------------
 .../frontend/web/js/proceed-to-checkout.js    | 27 +++++++++++++++++++
 .../view/frontend/web/js/view/minicart.js     |  6 +++--
 .../view/frontend/web/js/action/login.js      |  2 +-
 6 files changed, 48 insertions(+), 34 deletions(-)
 create mode 100644 app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js

diff --git a/app/code/Magento/Checkout/Block/Cart/Sidebar.php b/app/code/Magento/Checkout/Block/Cart/Sidebar.php
index 91f23b64334..6e16041c3a0 100644
--- a/app/code/Magento/Checkout/Block/Cart/Sidebar.php
+++ b/app/code/Magento/Checkout/Block/Cart/Sidebar.php
@@ -159,4 +159,14 @@ class Sidebar extends AbstractCart
     {
         return $this->getUrl('customer/account/forgotpassword');
     }
+
+    /**
+     * Return base url.
+     *
+     * @return string
+     */
+    public function getBaseUrl()
+    {
+        return $this->_storeManager->getStore()->getBaseUrl();
+    }
 }
diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml
index 03322e3ab35..314e3038a05 100644
--- a/app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml
+++ b/app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml
@@ -49,23 +49,20 @@
             removeItemUrl: '<?=$block->getRemoveItemUrl()?>',
             imageTemplate: '<?= $block->getImageHtmlTemplate()?>',
             customerRegisterUrl: '<?= $block->getCustomerRegisterUrlUrl()?>',
-            customerForgotPasswordUrl: '<?= $block->getCustomerForgotPasswordUrl()?>'
+            customerForgotPasswordUrl: '<?= $block->getCustomerForgotPasswordUrl()?>',
+            baseUrl: '<?= $block->getBaseUrl()?>'
         };
     </script>
     <script type="text/x-magento-init">
     {
         "[data-block='minicart']": {
             "Magento_Ui/js/core/app": <?php echo $block->getJsLayout();?>
+        },
+        "*": {
+            "Magento_Ui/js/block-loader": "<?php echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
         }
     }
     </script>
-    <script>
-        require([
-            'Magento_Ui/js/block-loader'
-        ], function(blockLoader) {
-            blockLoader("<?php echo $block->getViewFileUrl('images/loader-1.gif'); ?>");
-        })
-    </script>
 </div>
 
 
diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/link.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/link.phtml
index eea34623804..72b8a5bf502 100644
--- a/app/code/Magento/Checkout/view/frontend/templates/onepage/link.phtml
+++ b/app/code/Magento/Checkout/view/frontend/templates/onepage/link.phtml
@@ -10,31 +10,9 @@
     <button type="button"
             data-role="proceed-to-checkout"
             title="<?php echo __('Proceed to Checkout') ?>"
+            data-mage-init='{"Magento_Checkout/js/proceed-to-checkout":{}}'
             class="action primary checkout<?php echo($block->isDisabled()) ? ' disabled' : ''; ?>"
             <?php if ($block->isDisabled()):?>disabled="disabled"<?php endif; ?>>
         <span><?php echo __('Proceed to Checkout') ?></span>
     </button>
-
-    <script>
-        require(
-            [
-                'jquery',
-                'Magento_Checkout/js/model/cart/authentication-popup',
-                'Magento_Customer/js/customer-data'
-            ],
-            function($, authenticationPopup, customerData) {
-                $('button[data-role="proceed-to-checkout"]').click(function(event) {
-                    event.preventDefault();
-                    var cart = customerData.get('cart'),
-                        customer = customerData.get('customer');
-
-                    if (customer() == false && !cart().isGuestCheckoutAllowed) {
-                        authenticationPopup.showModal();
-                        return false;
-                    }
-                    location.href = window.checkout.checkoutUrl;
-                });
-            }
-        );
-    </script>
 <?php endif?>
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js
new file mode 100644
index 00000000000..87794967ddf
--- /dev/null
+++ b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js
@@ -0,0 +1,27 @@
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+define([
+        'jquery',
+        'Magento_Checkout/js/model/cart/authentication-popup',
+        'Magento_Customer/js/customer-data'
+    ],
+    function($, authenticationPopup, customerData) {
+        return function (config, element) {
+            $(element).click(function(event) {
+                event.preventDefault();
+                var cart = customerData.get('cart'),
+                    customer = customerData.get('customer');
+
+                if (customer() == false && !cart().isGuestCheckoutAllowed) {
+                    authenticationPopup.showModal();
+                    return false;
+                }
+                location.href = window.checkout.checkoutUrl;
+            });
+
+        };
+    }
+);
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 322718862d9..5ecb8fa64fc 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
@@ -6,11 +6,13 @@ define([
     'uiComponent',
     'Magento_Customer/js/customer-data',
     'jquery',
-    'ko'
-], function (Component, customerData, $, ko) {
+    'ko',
+    'mage/url'
+], function (Component, customerData, $, ko, url) {
     'use strict';
 
     var sidebarInitialized = false;
+    url.setBaseUrl(window.checkout.baseUrl);
 
     function initSidebar() {
         var minicart = $("[data-block='minicart']");
diff --git a/app/code/Magento/Customer/view/frontend/web/js/action/login.js b/app/code/Magento/Customer/view/frontend/web/js/action/login.js
index 743ec6d2f55..31d92882541 100644
--- a/app/code/Magento/Customer/view/frontend/web/js/action/login.js
+++ b/app/code/Magento/Customer/view/frontend/web/js/action/login.js
@@ -15,7 +15,7 @@ define(
         var callbacks = [],
             action = function(loginData, redirectUrl) {
                 return storage.post(
-                    '/customer/ajax/login',
+                    'customer/ajax/login',
                     JSON.stringify(loginData)
                 ).done(function (response) {
                     if (response.errors) {
-- 
GitLab