Skip to content

Commit

Permalink
MAGETWO-39865: [GITHUB] window.checkout is undefined if minicart is r…
Browse files Browse the repository at this point in the history
…emoved #1458
  • Loading branch information
Stanislav Idolov committed Jul 10, 2015
1 parent 24b7c6a commit 121d146
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 45 deletions.
22 changes: 0 additions & 22 deletions app/code/Magento/Checkout/Block/Cart/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public function getConfig()
'updateItemQtyUrl' => $this->getUpdateItemQtyUrl(),
'removeItemUrl' => $this->getRemoveItemUrl(),
'imageTemplate' => $this->getImageHtmlTemplate(),
'customerRegisterUrl' => $this->getCustomerRegisterUrlUrl(),
'customerForgotPasswordUrl' => $this->getCustomerForgotPasswordUrl(),
'baseUrl' => $this->getBaseUrl()
];
}
Expand Down Expand Up @@ -159,26 +157,6 @@ public function getTotalsHtml()
return $this->getLayout()->getBlock('checkout.cart.minicart.totals')->toHtml();
}

/**
* Get customer register url
*
* @return string
*/
public function getCustomerRegisterUrlUrl()
{
return $this->getUrl('customer/account/create');
}

/**
* Get customer forgot password url
*
* @return string
*/
public function getCustomerForgotPasswordUrl()
{
return $this->getUrl('customer/account/forgotpassword');
}

/**
* Return base url.
*
Expand Down
13 changes: 0 additions & 13 deletions app/code/Magento/Checkout/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@
<item name="displayArea" xsi:type="string">promotion</item>
</item>
</item>
<item name="sign-in-popup" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/cart/authentication</item>
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">sign-in-popup</item>
<item name="template" xsi:type="string">Magento_Checkout/cart/authentication</item>
</item>
<item name="children" xsi:type="array">
<item name="messages" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/view/messages</item>
<item name="displayArea" xsi:type="string">messages</item>
</item>
</item>
</item>
</item>
</item>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

define([
'jquery',
'Magento_Checkout/js/model/cart/authentication-popup',
'Magento_Customer/js/model/authentication-popup',
'Magento_Customer/js/customer-data'
],
function($, authenticationPopup, customerData) {
Expand All @@ -19,7 +19,7 @@ define([
authenticationPopup.showModal();
return false;
}
location.href = window.checkout.checkoutUrl;
location.href = window.authorizationPopup.checkoutUrl;
});

};
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/*global confirm:true*/
define([
"jquery",
'Magento_Checkout/js/model/cart/authentication-popup',
'Magento_Customer/js/model/authentication-popup',
'Magento_Customer/js/customer-data',
"jquery/ui",
"mage/decorate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ define([
'Magento_Customer/js/customer-data',
'jquery',
'ko',
'mage/url',
'sidebar'
], function (Component, customerData, $, ko, url) {
], function (Component, customerData, $, ko) {
'use strict';

var sidebarInitialized = false;
var addToCartCalls = 0;
url.setBaseUrl(window.checkout.baseUrl);

function initSidebar() {
var minicart = $("[data-block='minicart']");
Expand Down
89 changes: 89 additions & 0 deletions app/code/Magento/Customer/Block/Account/AuthorizationPopup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Block\Account;

class AuthorizationPopup extends \Magento\Framework\View\Element\Template
{
/**
* @var array
*/
protected $jsLayout;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
$this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
}

/**
* @return string
*/
public function getJsLayout()
{
return \Zend_Json::encode($this->jsLayout);
}

/**
* Returns popup config
*
* @return array
*/
public function getConfig()
{
return [
'checkoutUrl' => $this->getCheckoutUrl(),
'customerRegisterUrl' => $this->getCustomerRegisterUrlUrl(),
'customerForgotPasswordUrl' => $this->getCustomerForgotPasswordUrl(),
'baseUrl' => $this->getBaseUrl()
];
}

/**
* Return base url.
*
* @return string
*/
public function getBaseUrl()
{
return $this->_storeManager->getStore()->getBaseUrl();
}

/**
* Get one page checkout page url
*
* @return string
*/
public function getCheckoutUrl()
{
return $this->getUrl('checkout');
}

/**
* Get customer register url
*
* @return string
*/
public function getCustomerRegisterUrlUrl()
{
return $this->getUrl('customer/account/create');
}

/**
* Get customer forgot password url
*
* @return string
*/
public function getCustomerForgotPasswordUrl()
{
return $this->getUrl('customer/account/forgotpassword');
}
}
17 changes: 17 additions & 0 deletions app/code/Magento/Customer/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
</block>
<block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link"
template="account/link/authorization.phtml"/>
<block class="Magento\Customer\Block\Account\AuthorizationPopup" name="authorization-popup" as="authorization-popup" template="account/authorization-popup.phtml">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="authorizationPopup" xsi:type="array">
<item name="component" xsi:type="string">Magento_Customer/js/view/authentication-popup</item>
<item name="children" xsi:type="array">
<item name="messages" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/view/messages</item>
<item name="displayArea" xsi:type="string">messages</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</block>
</referenceBlock>
<referenceContainer name="content">
<block name="customer.section.config" class="Magento\Customer\Block\SectionConfig"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<div id="authorizationPopup" data-bind="scope:'authorizationPopup'">
<script>
window.authorizationPopup = <?php echo \Zend_Json::encode($block->getConfig()); ?>;
</script>
<!-- ko template: getTemplate() --><!-- /ko -->
<script type="text/x-magento-init">
{
"#authorizationPopup": {
"Magento_Ui/js/core/app": <?php echo $block->getJsLayout();?>
},
"*": {
"Magento_Ui/js/block-loader": "<?php echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
}
}
</script>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@ define(
'Magento_Ui/js/form/form',
'Magento_Customer/js/action/login',
'Magento_Customer/js/customer-data',
'Magento_Checkout/js/model/cart/authentication-popup',
'Magento_Customer/js/model/authentication-popup',
'mage/translate',
'mage/url',
'mage/validation'
],
function($, ko, Component, loginAction, customerData, authenticationPopup, $t) {
function($, ko, Component, loginAction, customerData, authenticationPopup, $t, url) {
'use strict';
return Component.extend({
registerUrl: window.checkout.customerRegisterUrl,
forgotPasswordUrl: window.checkout.customerForgotPasswordUrl,
registerUrl: window.authorizationPopup.customerRegisterUrl,
forgotPasswordUrl: window.authorizationPopup.customerForgotPasswordUrl,
modalWindow: null,
isLoading: ko.observable(false),

defaults: {
template: 'Magento_Customer/authentication-popup'
},

initialize: function() {
var self = this;
this._super();
url.setBaseUrl(window.authorizationPopup.baseUrl);
loginAction.registerLoginCallback(function() {
self.isLoading(false);
});
Expand Down

0 comments on commit 121d146

Please sign in to comment.