Skip to content

Commit

Permalink
Merge pull request #608 from magento-folks/bugs
Browse files Browse the repository at this point in the history
[Folks]Bugfixes
  • Loading branch information
Korshenko, Oleksii(okorshenko) committed May 13, 2016
2 parents fc32492 + 5c82f8c commit 584af4d
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 60 deletions.
27 changes: 22 additions & 5 deletions app/code/Magento/Checkout/Controller/Account/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
"config": {
"registrationUrl": "<?php /* @escapeNotVerified */ echo $block->getCreateAccountUrl(); ?>",
"email": "<?php /* @escapeNotVerified */ echo $block->getEmailAddress(); ?>"
},
"children": {
"errors": {
"component": "Magento_Ui/js/view/messages",
"sortOrder": 0,
"displayArea": "messages",
"config": {
"autoHideTimeOut": -1
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ define(
*/
postcodeValidation: function () {
var countryId = $('select[name="country_id"]').val(),
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId),
validationResult,
warnMessage;

if (postcodeElement == null || postcodeElement.value() == null) {
return true;
}

postcodeElement.warn(null);
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId);

if (!validationResult) {
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -18,7 +16,7 @@ define(
'Magento_Checkout/js/model/checkout-data-resolver',
'mage/validation'
],
function(
function (
$,
Component,
selectShippingAddress,
Expand All @@ -31,6 +29,7 @@ define(
checkoutDataResolver
) {
'use strict';

return Component.extend({
defaults: {
template: 'Magento_Checkout/cart/shipping-estimation'
Expand All @@ -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);
Expand All @@ -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;
},

/**
Expand All @@ -83,6 +95,7 @@ define(
*/
getEstimationInfo: function () {
var addressData = null;

this.source.set('params.invalid', false);
this.source.trigger('shippingAddress.data.validate');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define(
checkoutData
) {
'use strict';

return Component.extend({
defaults: {
template: 'Magento_Checkout/cart/shipping-rates'
Expand Down Expand Up @@ -86,6 +87,7 @@ define(
selectShippingMethod: function (methodData) {
selectShippingMethodAction(methodData);
checkoutData.setSelectedShippingRate(methodData['carrier_code'] + '_' + methodData['method_code']);

return true;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
"/>
<label class="label" data-bind="attr: {for: 's_method_' + method_code}">
<!-- ko text: method_title --><!-- /ko -->
<!-- ko text: $data.method_title --><!-- /ko -->
<!-- ko text: $parents[1].getFormattedPrice(amount) --><!-- /ko -->
</label>
<!-- /ko -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* See COPYING.txt for license details.
*/
-->
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div>
<!-- ko ifnot: accountCreated -->
<!-- ko if: isFormVisible -->
<p data-bind="i18n: 'You can track your order status by creating an account.'"></p>
<p><span data-bind="i18n: 'Email Address'"></span>: <span data-bind="text: getEmailAddress()"></span></p>
<form method="post" data-bind="submit: createAccount">
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/CheckoutAgreements/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<type name="Magento\Checkout\Api\PaymentInformationManagementInterface">
<plugin name="validate-agreements" type="Magento\CheckoutAgreements\Model\Checkout\Plugin\Validation"/>
</type>
<preference for="Magento\Checkout\Api\AgreementsValidatorInterface" type="Magento\CheckoutAgreements\Model\AgreementsValidator" />
</config>
1 change: 0 additions & 1 deletion app/code/Magento/CheckoutAgreements/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
</argument>
</arguments>
</type>
<preference for="Magento\Checkout\Api\AgreementsValidatorInterface" type="Magento\CheckoutAgreements\Model\AgreementsValidator" />
</config>
Loading

0 comments on commit 584af4d

Please sign in to comment.