diff --git a/app/code/Magento/Captcha/Model/Cart/ConfigPlugin.php b/app/code/Magento/Captcha/Model/Cart/ConfigPlugin.php new file mode 100644 index 0000000000000000000000000000000000000000..26ecd5b91ac72566448c203fc8ea969f0e612538 --- /dev/null +++ b/app/code/Magento/Captcha/Model/Cart/ConfigPlugin.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Captcha\Model\Cart; + +class ConfigPlugin +{ + /** + * @var \Magento\Captcha\Model\Checkout\ConfigProvider + */ + protected $configProvider; + + /** + * @param \Magento\Captcha\Model\Checkout\ConfigProvider $configProvider + */ + public function __construct( + \Magento\Captcha\Model\Checkout\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/Captcha/etc/di.xml b/app/code/Magento/Captcha/etc/di.xml index 3955d289f46d75edeccea90430580d404ad92cb5..6dfdcd70b2222544e04939b7eb1aa4404dd07083 100644 --- a/app/code/Magento/Captcha/etc/di.xml +++ b/app/code/Magento/Captcha/etc/di.xml @@ -27,4 +27,7 @@ </argument> </arguments> </type> + <type name="Magento\Checkout\Block\Cart\Sidebar"> + <plugin name="login_captcha" type="\Magento\Captcha\Model\Cart\ConfigPlugin" sortOrder="50" /> + </type> </config> diff --git a/app/code/Magento/Captcha/view/frontend/layout/checkout_onepage_index.xml b/app/code/Magento/Captcha/view/frontend/layout/checkout_onepage_index.xml index 85765bdf58c811aebda09bab5d1e7676a6a147c3..d7d6fc551c5ff3f777effb8a6cf3b573c60113a1 100644 --- a/app/code/Magento/Captcha/view/frontend/layout/checkout_onepage_index.xml +++ b/app/code/Magento/Captcha/view/frontend/layout/checkout_onepage_index.xml @@ -19,6 +19,7 @@ <item name="component" xsi:type="string">Magento_Captcha/js/view/checkout/loginCaptcha</item> <item name="displayArea" xsi:type="string">additional-login-form-fields</item> <item name="formId" xsi:type="string">user_login</item> + <item name="configSource" xsi:type="string">checkoutConfig</item> </item> </item> </item> @@ -36,6 +37,7 @@ <item name="component" xsi:type="string">Magento_Captcha/js/view/checkout/loginCaptcha</item> <item name="displayArea" xsi:type="string">additional-login-form-fields</item> <item name="formId" xsi:type="string">guest_checkout</item> + <item name="configSource" xsi:type="string">checkoutConfig</item> </item> </item> </item> @@ -57,6 +59,7 @@ <item name="component" xsi:type="string">Magento_Captcha/js/view/checkout/loginCaptcha</item> <item name="displayArea" xsi:type="string">additional-login-form-fields</item> <item name="formId" xsi:type="string">guest_checkout</item> + <item name="configSource" xsi:type="string">checkoutConfig</item> </item> </item> </item> diff --git a/app/code/Magento/Captcha/view/frontend/layout/default.xml b/app/code/Magento/Captcha/view/frontend/layout/default.xml new file mode 100644 index 0000000000000000000000000000000000000000..9e0bf3cc751c5c0b9fad96ea62e3da31b26ed320 --- /dev/null +++ b/app/code/Magento/Captcha/view/frontend/layout/default.xml @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> + <body> + <referenceBlock name="minicart"> + <arguments> + <argument name="jsLayout" xsi:type="array"> + <item name="components" xsi:type="array"> + <item name="minicart_content" xsi:type="array"> + <item name="children" xsi:type="array"> + <item name="sign-in-popup" xsi:type="array"> + <item name="children" xsi:type="array"> + <item name="captcha" xsi:type="array"> + <item name="component" xsi:type="string">Magento_Captcha/js/view/checkout/loginCaptcha</item> + <item name="displayArea" xsi:type="string">additional-login-form-fields</item> + <item name="formId" xsi:type="string">user_login</item> + <item name="configSource" xsi:type="string">checkout</item> + </item> + </item> + </item> + </item> + </item> + </item> + </argument> + </arguments> + </referenceBlock> + </body> +</page> diff --git a/app/code/Magento/Captcha/view/frontend/web/js/action/refresh.js b/app/code/Magento/Captcha/view/frontend/web/js/action/refresh.js index cc8b2119827216883b9330c5717d5cbf1d460337..b11ae9b1f144aee227da25267b86dd7cc7ed1681 100644 --- a/app/code/Magento/Captcha/view/frontend/web/js/action/refresh.js +++ b/app/code/Magento/Captcha/view/frontend/web/js/action/refresh.js @@ -9,9 +9,10 @@ define( function(storage) { "use strict"; return function(refreshUrl, formId, imageSource) { - storage.post( + return storage.post( refreshUrl, - JSON.stringify({'formId': formId}) + JSON.stringify({'formId': formId}), + false ).done( function (response) { if (response.imgSrc) { diff --git a/app/code/Magento/Captcha/view/frontend/web/js/model/captcha.js b/app/code/Magento/Captcha/view/frontend/web/js/model/captcha.js index a8abae3cc8de7638c7c6414df11a646935e3e715..6a720a8cdeb91879729ecc3ca4aa85f3e497f3bd 100644 --- a/app/code/Magento/Captcha/view/frontend/web/js/model/captcha.js +++ b/app/code/Magento/Captcha/view/frontend/web/js/model/captcha.js @@ -6,10 +6,11 @@ /*global alert*/ define( [ + 'jquery', 'ko', 'Magento_Captcha/js/action/refresh' ], - function(ko, refreshAction) { + function($, ko, refreshAction) { return function (captchaData) { return { formId: captchaData.formId, @@ -20,6 +21,7 @@ define( isCaseSensitive: captchaData.isCaseSensitive, imageHeight: captchaData.imageHeight, refreshUrl: captchaData.refreshUrl, + isLoading: ko.observable(false), getFormId: function () { return this.formId; @@ -70,7 +72,14 @@ define( this.captchaValue(value); }, refresh: function() { - refreshAction(this.getRefreshUrl(), this.getFormId(), this.getImageSource()); + var refresh, + self = this; + this.isLoading(true); + + refresh = refreshAction(this.getRefreshUrl(), this.getFormId(), this.getImageSource()); + $.when(refresh).done(function() { + self.isLoading(false); + }); } }; } diff --git a/app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js b/app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js index b2de3a1cd517d104720641c65cc9bfb2d9a91363..ddb4a6f84ae57bf22a0c9396a5843658813f0785 100644 --- a/app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js +++ b/app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js @@ -7,14 +7,14 @@ define( [ 'jquery', - 'ko', 'uiComponent', 'Magento_Captcha/js/model/captcha', 'Magento_Captcha/js/model/captchaList' ], - function ($, ko, Component, Captcha, captchaList) { - "use strict"; - var captchaConfig = window.checkoutConfig.captcha; + function ($, Component, Captcha, captchaList) { + 'use strict'; + var captchaConfig; + return Component.extend({ defaults: { template: 'Magento_Captcha/checkout/captcha' @@ -25,11 +25,16 @@ define( return this.currentCaptcha.getCaptchaValue(); }, initialize: function() { + this._super(); + captchaConfig = window[this.configSource]['captcha']; + $.each(captchaConfig, function(formId, captchaData) { captchaData.formId = formId; captchaList.add(Captcha(captchaData)); }); - this._super(); + }, + getIsLoading: function() { + return this.currentCaptcha.isLoading }, getCurrentCaptcha: function() { return this.currentCaptcha; diff --git a/app/code/Magento/Captcha/view/frontend/web/template/checkout/captcha.html b/app/code/Magento/Captcha/view/frontend/web/template/checkout/captcha.html index fd345b82386446b5553ef81f3ce56b5e1c70f158..3b294d904b2cbe877dd80763986aa7fa66ecf89b 100644 --- a/app/code/Magento/Captcha/view/frontend/web/template/checkout/captcha.html +++ b/app/code/Magento/Captcha/view/frontend/web/template/checkout/captcha.html @@ -5,7 +5,7 @@ */ --> <!-- ko if: (isRequired() && getIsVisible())--> -<div class="field captcha required"> +<div class="field captcha required" data-bind="blockLoader: getIsLoading()"> <label data-bind="attr: {for: 'captcha_' + formId}" class="label"><span data-bind="text: $t('Please type the letters below')"></span></label> <div class="control captcha"> <input name="captcha_string" type="text" class="input-text required-entry" data-bind="value: captchaValue(), attr: {id: 'captcha_' + formId, 'data-scope': dataScope}" /> diff --git a/app/code/Magento/Checkout/Block/Cart/Sidebar.php b/app/code/Magento/Checkout/Block/Cart/Sidebar.php index 6e16041c3a0fd8b9548b4c05a3421a7e70a5079e..a754a3c6582c58f3a1dcd4ec8f90f234a2ffaeff 100644 --- a/app/code/Magento/Checkout/Block/Cart/Sidebar.php +++ b/app/code/Magento/Checkout/Block/Cart/Sidebar.php @@ -52,6 +52,25 @@ class Sidebar extends AbstractCart $this->imageView = $imageView; } + /** + * Returns minicart config + * + * @return array + */ + public function getConfig() + { + return [ + 'shoppingCartUrl' => $this->getShoppingCartUrl(), + 'checkoutUrl' => $this->getCheckoutUrl(), + 'updateItemQtyUrl' => $this->getUpdateItemQtyUrl(), + 'removeItemUrl' => $this->getRemoveItemUrl(), + 'imageTemplate' => $this->getImageHtmlTemplate(), + 'customerRegisterUrl' => $this->getCustomerRegisterUrlUrl(), + 'customerForgotPasswordUrl' => $this->getCustomerForgotPasswordUrl(), + 'baseUrl' => $this->getBaseUrl() + ]; + } + /** * @return string */ 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 314e3038a0555a7d95715e8f27fbefd260c89e00..6d08bcb4bbf500ef2f823c46e8074640099f07d6 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml @@ -42,16 +42,7 @@ </div> <?php endif ?> <script> - window.checkout = { - shoppingCartUrl: '<?=$block->getShoppingCartUrl()?>', - checkoutUrl: '<?=$block->getCheckoutUrl()?>', - updateItemQtyUrl: '<?=$block->getUpdateItemQtyUrl()?>', - removeItemUrl: '<?=$block->getRemoveItemUrl()?>', - imageTemplate: '<?= $block->getImageHtmlTemplate()?>', - customerRegisterUrl: '<?= $block->getCustomerRegisterUrlUrl()?>', - customerForgotPasswordUrl: '<?= $block->getCustomerForgotPasswordUrl()?>', - baseUrl: '<?= $block->getBaseUrl()?>' - }; + window.checkout = <?php echo \Zend_Json::encode($block->getConfig()); ?>; </script> <script type="text/x-magento-init"> {