diff --git a/app/code/Magento/Checkout/Controller/Account/Create.php b/app/code/Magento/Checkout/Controller/Account/Create.php index 00f8eba166207..5dd201b8b1066 100644 --- a/app/code/Magento/Checkout/Controller/Account/Create.php +++ b/app/code/Magento/Checkout/Controller/Account/Create.php @@ -50,21 +50,38 @@ public function __construct( * @throws AlreadyExistsException * @throws NoSuchEntityException * @throws \Exception - * @return void + * @return \Magento\Framework\Controller\Result\Json */ public function execute() { + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->_objectManager->get(\Magento\Framework\Controller\Result\JsonFactory::class)->create(); + if ($this->customerSession->isLoggedIn()) { - $this->messageManager->addError(__("Customer is already registered")); - return; + return $resultJson->setData( + [ + 'errors' => true, + 'message' => __('Customer is already registered') + ] + ); } $orderId = $this->checkoutSession->getLastOrderId(); if (!$orderId) { - $this->messageManager->addError(__("Your session has expired")); - return; + return $resultJson->setData( + [ + 'errors' => true, + 'message' => __('Your session has expired') + ] + ); } try { $this->orderCustomerService->create($orderId); + return $resultJson->setData( + [ + 'errors' => false, + 'message' => __('A letter with further instructions will be sent to your email.') + ] + ); } catch (\Exception $e) { $this->messageManager->addException($e, $e->getMessage()); throw $e; diff --git a/app/code/Magento/Checkout/Test/Unit/Controller/Account/CreateTest.php b/app/code/Magento/Checkout/Test/Unit/Controller/Account/CreateTest.php index 31f1fffa67536..154070dd0afc7 100644 --- a/app/code/Magento/Checkout/Test/Unit/Controller/Account/CreateTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Controller/Account/CreateTest.php @@ -35,6 +35,11 @@ class CreateTest extends \PHPUnit_Framework_TestCase */ protected $orderCustomerService; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $objectManagerMock; + protected function setUp() { $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -49,33 +54,77 @@ protected function setUp() ); $this->messageManager = $this->getMock('\Magento\Framework\Message\ManagerInterface'); + $this->objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); + $contextMock = $this->getMock( + \Magento\Framework\App\Action\Context::class, + ['getObjectManager'], + [], + '', + false + ); + $contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock); + $this->action = $objectManagerHelper->getObject( 'Magento\Checkout\Controller\Account\Create', [ 'checkoutSession' => $this->checkoutSession, 'customerSession' => $this->customerSession, 'orderCustomerService' => $this->orderCustomerService, - 'messageManager' => $this->messageManager - + 'messageManager' => $this->messageManager, + 'context' => $contextMock ] ); } public function testExecuteAddsSessionMessageIfCustomerIsLoggedIn() { + $jsonFactoryMock = $this->getMock(\Magento\Framework\Controller\Result\JsonFactory::class, [], [], '', false); + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->with(\Magento\Framework\Controller\Result\JsonFactory::class) + ->willReturn($jsonFactoryMock); + $jsonMock = $this->getMock(\Magento\Framework\Controller\Result\Json::class, [], [], '', false); + $jsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock); + $this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); - $this->messageManager->expects($this->once())->method('addError')->with(); + + $jsonMock->expects($this->once()) + ->method('setData') + ->with( + [ + 'errors' => true, + 'message' => __('Customer is already registered') + ] + )->willReturnSelf(); $this->action->execute(); } public function testExecute() { + $jsonFactoryMock = $this->getMock(\Magento\Framework\Controller\Result\JsonFactory::class, [], [], '', false); + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->with(\Magento\Framework\Controller\Result\JsonFactory::class) + ->willReturn($jsonFactoryMock); + $jsonMock = $this->getMock(\Magento\Framework\Controller\Result\Json::class, [], [], '', false); + $jsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock); + $this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->checkoutSession->expects($this->once())->method('getLastOrderId')->will($this->returnValue(100)); $customer = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface'); $this->orderCustomerService->expects($this->once())->method('create')->with(100)->will( $this->returnValue($customer) ); + + $jsonMock->expects($this->once()) + ->method('setData') + ->with( + [ + 'errors' => false, + 'message' => __('A letter with further instructions will be sent to your email.') + ] + )->willReturnSelf(); + $this->action->execute(); } } diff --git a/app/code/Magento/Checkout/view/frontend/templates/registration.phtml b/app/code/Magento/Checkout/view/frontend/templates/registration.phtml index fdcd02c219565..40edfa6cd3c29 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/registration.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/registration.phtml @@ -19,6 +19,16 @@ "config": { "registrationUrl": "getCreateAccountUrl(); ?>", "email": "getEmailAddress(); ?>" + }, + "children": { + "errors": { + "component": "Magento_Ui/js/view/messages", + "sortOrder": 0, + "displayArea": "messages", + "config": { + "autoHideTimeOut": -1 + } + } } } } diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js index 558b7d6585b91..9b82199abbd33 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js @@ -135,7 +135,7 @@ define( */ postcodeValidation: function () { var countryId = $('select[name="country_id"]').val(), - validationResult = postcodeValidator.validate(postcodeElement.value(), countryId), + validationResult, warnMessage; if (postcodeElement == null || postcodeElement.value() == null) { @@ -143,6 +143,7 @@ define( } postcodeElement.warn(null); + validationResult = postcodeValidator.validate(postcodeElement.value(), countryId); if (!validationResult) { warnMessage = $t('Provided Zip/Postal Code seems to be invalid.'); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-estimation.js b/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-estimation.js index 72f71819e701b..08641f015f609 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-estimation.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-estimation.js @@ -2,8 +2,6 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -/*jshint browser:true jquery:true*/ -/*global alert*/ define( [ 'jquery', @@ -18,7 +16,7 @@ define( 'Magento_Checkout/js/model/checkout-data-resolver', 'mage/validation' ], - function( + function ( $, Component, selectShippingAddress, @@ -31,6 +29,7 @@ define( checkoutDataResolver ) { 'use strict'; + return Component.extend({ defaults: { template: 'Magento_Checkout/cart/shipping-estimation' @@ -43,18 +42,23 @@ define( initialize: function () { this._super(); registry.async('checkoutProvider')(function (checkoutProvider) { + var address, estimatedAddress; + checkoutDataResolver.resolveEstimationAddress(); - var address = quote.isVirtual() ? quote.billingAddress() : quote.shippingAddress(), - estimatedAddress; + address = quote.isVirtual() ? quote.billingAddress() : quote.shippingAddress(); + if (address) { - estimatedAddress = address.isEditable() - ? addressConverter.quoteAddressToFormAddressData(address) - : addressConverter.quoteAddressToFormAddressData(addressConverter.addressToEstimationAddress(address)); + estimatedAddress = address.isEditable() ? + addressConverter.quoteAddressToFormAddressData(address) : + addressConverter.quoteAddressToFormAddressData( + addressConverter.addressToEstimationAddress(address) + ); checkoutProvider.set( 'shippingAddress', $.extend({}, checkoutProvider.get('shippingAddress'), estimatedAddress) ); } + if (!quote.isVirtual()) { checkoutProvider.on('shippingAddress', function (shippingAddressData) { checkoutData.setShippingAddressFromData(shippingAddressData); @@ -65,16 +69,24 @@ define( }); } }); - }, + return this; + }, /** * @override */ - initElement: function(element) { + initElement: function (element) { + this._super(); + if (element.index === 'address-fieldsets') { shippingRatesValidator.bindChangeHandlers(element.elems(), true, 500); + element.elems.subscribe(function (elems) { + shippingRatesValidator.doElementBinding(elems[elems.length - 1], true, 500); + }); } + + return this; }, /** @@ -83,6 +95,7 @@ define( */ getEstimationInfo: function () { var addressData = null; + this.source.set('params.invalid', false); this.source.trigger('shippingAddress.data.validate'); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js b/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js index 12a0707ac7548..24b4ea01fe1a3 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js @@ -24,6 +24,7 @@ define( checkoutData ) { 'use strict'; + return Component.extend({ defaults: { template: 'Magento_Checkout/cart/shipping-rates' @@ -86,6 +87,7 @@ define( selectShippingMethod: function (methodData) { selectShippingMethodAction(methodData); checkoutData.setSelectedShippingRate(methodData['carrier_code'] + '_' + methodData['method_code']); + return true; } }); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/registration.js b/app/code/Magento/Checkout/view/frontend/web/js/view/registration.js index e50fe4d932708..b0ca42fc09745 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/registration.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/registration.js @@ -5,30 +5,63 @@ /*jshint browser:true jquery:true*/ /*global alert*/ define( - ['jquery', 'uiComponent'], - function ($, Component) { + [ + 'jquery', + 'uiComponent', + 'Magento_Ui/js/model/messageList' + ], + function ($, Component, messageList) { 'use strict'; + return Component.extend({ defaults: { template: 'Magento_Checkout/registration', accountCreated: false, - creationStarted: false + creationStarted: false, + isFormVisible: true }, - /** Initialize observable properties */ + + /** + * Initialize observable properties + */ initObservable: function () { this._super() .observe('accountCreated') + .observe('isFormVisible') .observe('creationStarted'); + return this; }, - getEmailAddress: function() { + + /** + * @return {*} + */ + getEmailAddress: function () { return this.email; }, - createAccount: function() { + + /** + * Create new user account + */ + createAccount: function () { this.creationStarted(true); - $.post(this.registrationUrl).done( - function() { - this.accountCreated(true) + $.post( + this.registrationUrl + ).done( + function (response) { + + if (response.errors == false) { + this.accountCreated(true) + } else { + messageList.addErrorMessage(response); + } + this.isFormVisible(false); + }.bind(this) + ).fail( + function (response) { + this.accountCreated(false) + this.isFormVisible(false); + messageList.addErrorMessage(response); }.bind(this) ); } diff --git a/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html b/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html index a8f01d98a117c..439a9338d9d01 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html @@ -29,7 +29,7 @@ } "/> diff --git a/app/code/Magento/Checkout/view/frontend/web/template/registration.html b/app/code/Magento/Checkout/view/frontend/web/template/registration.html index 1eca19d3bf1ad..10c4a76ccd69a 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/registration.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/registration.html @@ -4,8 +4,11 @@ * See COPYING.txt for license details. */ --> + + +
- +

:

diff --git a/app/code/Magento/CheckoutAgreements/etc/di.xml b/app/code/Magento/CheckoutAgreements/etc/di.xml index cb9b914369e1b..d4c4b95479720 100644 --- a/app/code/Magento/CheckoutAgreements/etc/di.xml +++ b/app/code/Magento/CheckoutAgreements/etc/di.xml @@ -18,4 +18,5 @@ + diff --git a/app/code/Magento/CheckoutAgreements/etc/frontend/di.xml b/app/code/Magento/CheckoutAgreements/etc/frontend/di.xml index 0180e74b82737..c462e6c812df4 100644 --- a/app/code/Magento/CheckoutAgreements/etc/frontend/di.xml +++ b/app/code/Magento/CheckoutAgreements/etc/frontend/di.xml @@ -13,5 +13,4 @@ - diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php index 3114c181f1551..d27882770328a 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php @@ -18,6 +18,7 @@ class Created extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacken /** * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime * @codeCoverageIgnore + * @deprecated Remove unused dependency */ public function __construct(\Magento\Framework\Stdlib\DateTime\DateTime $dateTime) { @@ -34,8 +35,10 @@ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); if ($object->isObjectNew() && $object->getData($attributeCode) === null) { - //$object->setData($attributeCode, $this->dateTime->gmtDate()); - $object->setData($attributeCode, gmdate('Y-m-d H:i:s')); + $object->setData( + $attributeCode, + gmdate(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); } return $this; diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php index 97a9223a7d3f9..bf4cbd92b3b76 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php @@ -18,6 +18,7 @@ class Updated extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacken /** * @param \Magento\Framework\Stdlib\DateTime $dateTime * @codeCoverageIgnore + * @deprecated Remove unused dependency */ public function __construct(\Magento\Framework\Stdlib\DateTime $dateTime) { diff --git a/app/code/Magento/GiftMessage/view/frontend/web/js/view/gift-message.js b/app/code/Magento/GiftMessage/view/frontend/web/js/view/gift-message.js index 3cd94639436ba..5d58e0a21fe18 100644 --- a/app/code/Magento/GiftMessage/view/frontend/web/js/view/gift-message.js +++ b/app/code/Magento/GiftMessage/view/frontend/web/js/view/gift-message.js @@ -3,30 +3,40 @@ * See COPYING.txt for license details. */ /*global define*/ -define([ +define( + [ 'uiComponent', 'Magento_GiftMessage/js/model/gift-message', 'Magento_GiftMessage/js/model/gift-options', 'Magento_GiftMessage/js/action/gift-options' ], - function (Component, giftMessage, giftOptions, giftOptionsService) { - "use strict"; + function (Component, GiftMessage, giftOptions, giftOptionsService) { + 'use strict'; + return Component.extend({ formBlockVisibility: null, resultBlockVisibility: null, model: {}, - initialize: function() { - var self = this; + + /** + * Component init + */ + initialize: function () { + var self = this, + model; + this._super() .observe('formBlockVisibility') - .observe({'resultBlockVisibility': false}); + .observe({ + 'resultBlockVisibility': false + }); this.itemId = this.itemId || 'orderLevel'; - var model = new giftMessage(this.itemId); + model = new GiftMessage(this.itemId); giftOptions.addOption(model); this.model = model; - this.model.getObservable('isClear').subscribe(function(value) { + this.model.getObservable('isClear').subscribe(function (value) { if (value == true) { self.formBlockVisibility(false); self.model.getObservable('alreadyAdded')(true); @@ -35,52 +45,95 @@ define([ this.isResultBlockVisible(); }, - isResultBlockVisible: function() { + + /** + * Is reslt block visible + */ + isResultBlockVisible: function () { var self = this; + if (this.model.getObservable('alreadyAdded')()) { this.resultBlockVisibility(true); } - this.model.getObservable('additionalOptionsApplied').subscribe(function(value) { + this.model.getObservable('additionalOptionsApplied').subscribe(function (value) { if (value == true) { self.resultBlockVisibility(true); } }); }, - getObservable: function(key) { + + /** + * @param {String} key + * @return {*} + */ + getObservable: function (key) { return this.model.getObservable(key); }, - toggleFormBlockVisibility: function() { + + /** + * Hide\Show form block + */ + toggleFormBlockVisibility: function () { if (!this.model.getObservable('alreadyAdded')()) { this.formBlockVisibility(!this.formBlockVisibility()); + } else { + this.resultBlockVisibility(!this.resultBlockVisibility()); } }, - editOptions: function() { + + /** + * Edit options + */ + editOptions: function () { this.resultBlockVisibility(false); this.formBlockVisibility(true); }, - deleteOptions: function() { + + /** + * Delete options + */ + deleteOptions: function () { giftOptionsService(this.model, true); }, - hideFormBlock: function() { + + /** + * Hide form block + */ + hideFormBlock: function () { this.formBlockVisibility(false); + if (this.model.getObservable('alreadyAdded')()) { this.resultBlockVisibility(true); } }, - hasActiveOptions: function() { - var regionData = this.getRegion('additionalOptions'); - var options = regionData(); + + /** + * @return {Boolean} + */ + hasActiveOptions: function () { + var regionData = this.getRegion('additionalOptions'), + options = regionData(); + for (var i = 0; i < options.length; i++) { if (options[i].isActive()) { return true; } } + return false; }, - isActive: function() { + + /** + * @return {Boolean} + */ + isActive: function () { return this.model.isGiftMessageAvailable(); }, - submitOptions: function() { + + /** + * Submit options + */ + submitOptions: function () { giftOptionsService(this.model); } }); diff --git a/app/code/Magento/Persistent/Observer/SynchronizePersistentInfoObserver.php b/app/code/Magento/Persistent/Observer/SynchronizePersistentInfoObserver.php index 04ce94603573b..23123d549b643 100644 --- a/app/code/Magento/Persistent/Observer/SynchronizePersistentInfoObserver.php +++ b/app/code/Magento/Persistent/Observer/SynchronizePersistentInfoObserver.php @@ -6,7 +6,6 @@ namespace Magento\Persistent\Observer; use Magento\Framework\Event\Observer; - use Magento\Framework\Event\ObserverInterface; /** @@ -55,6 +54,7 @@ public function __construct( * * @param Observer $observer * @return void + * @deprecated */ public function execute(Observer $observer) { diff --git a/app/code/Magento/Persistent/etc/frontend/events.xml b/app/code/Magento/Persistent/etc/frontend/events.xml index b66cc3baefbbd..eb5c92e7d08e2 100644 --- a/app/code/Magento/Persistent/etc/frontend/events.xml +++ b/app/code/Magento/Persistent/etc/frontend/events.xml @@ -12,9 +12,6 @@ - - - diff --git a/app/code/Magento/SalesRule/view/frontend/web/template/cart/totals/discount.html b/app/code/Magento/SalesRule/view/frontend/web/template/cart/totals/discount.html index ec51d0f38d263..6b5d134ea5b24 100644 --- a/app/code/Magento/SalesRule/view/frontend/web/template/cart/totals/discount.html +++ b/app/code/Magento/SalesRule/view/frontend/web/template/cart/totals/discount.html @@ -6,7 +6,10 @@ --> - + + + + diff --git a/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt b/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt index 139be106d38e4..c1f91eec45b72 100644 --- a/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt +++ b/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt @@ -113,7 +113,6 @@ app/code/Magento/Checkout/view/frontend/web/js/view/authentication-messages.js app/code/Magento/Checkout/view/frontend/web/js/view/authentication.js app/code/Magento/Checkout/view/frontend/web/js/view/beforePlaceOrder.js app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js -app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-estimation.js app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js app/code/Magento/Checkout/view/frontend/web/js/view/cart/totals.js app/code/Magento/Checkout/view/frontend/web/js/view/cart/totals/shipping.js @@ -675,7 +674,6 @@ vendor/magento/module-checkout/view/frontend/web/js/sidebar.js vendor/magento/module-checkout/view/frontend/web/js/view/authentication.js vendor/magento/module-checkout/view/frontend/web/js/view/before-place-order.js vendor/magento/module-checkout/view/frontend/web/js/view/billing-address.js -vendor/magento/module-checkout/view/frontend/web/js/view/cart/shipping-estimation.js vendor/magento/module-checkout/view/frontend/web/js/view/cart/shipping-rates.js vendor/magento/module-checkout/view/frontend/web/js/view/cart/totals.js vendor/magento/module-checkout/view/frontend/web/js/view/cart/totals/shipping.js