diff --git a/app/code/Magento/Checkout/Model/PaymentInformationManagement.php b/app/code/Magento/Checkout/Model/PaymentInformationManagement.php index 79e76feb4366190cb1d81389e7c54ac4f97cca9e..4a0f502da20dfdc94545a81c20dfa061ffef0008 100644 --- a/app/code/Magento/Checkout/Model/PaymentInformationManagement.php +++ b/app/code/Magento/Checkout/Model/PaymentInformationManagement.php @@ -14,6 +14,7 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor { /** * @var \Magento\Quote\Api\BillingAddressManagementInterface + * @deprecated This call was substituted to eliminate extra quote::save call */ protected $billingAddressManagement; @@ -42,6 +43,11 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor */ private $logger; + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + private $cartRepository; + /** * @param \Magento\Quote\Api\BillingAddressManagementInterface $billingAddressManagement * @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement @@ -99,7 +105,19 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { if ($billingAddress) { - $this->billingAddressManagement->assign($cartId, $billingAddress); + /** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */ + $quoteRepository = $this->getCartRepository(); + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $quoteRepository->getActive($cartId); + $quote->removeAddress($quote->getBillingAddress()->getId()); + $quote->setBillingAddress($billingAddress); + $quote->setDataChanges(true); + $shippingAddress = $quote->getShippingAddress(); + if ($shippingAddress && $shippingAddress->getShippingMethod()) { + $shippingDataArray = explode('_', $shippingAddress->getShippingMethod()); + $shippingCarrier = array_shift($shippingDataArray); + $shippingAddress->setLimitCarrier($shippingCarrier); + } } $this->paymentMethodManagement->set($cartId, $paymentMethod); return true; @@ -130,4 +148,19 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor } return $this->logger; } + + /** + * Get Cart repository + * + * @return \Magento\Quote\Api\CartRepositoryInterface + * @deprecated + */ + private function getCartRepository() + { + if (!$this->cartRepository) { + $this->cartRepository = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Quote\Api\CartRepositoryInterface::class); + } + return $this->cartRepository; + } } diff --git a/app/code/Magento/Checkout/Model/ShippingInformationManagement.php b/app/code/Magento/Checkout/Model/ShippingInformationManagement.php index 237d28e2845e430493d1ba7f73b15160995c7c9c..1b4f8b8c64a864efefb03e56cd52aa8dbb41e304 100644 --- a/app/code/Magento/Checkout/Model/ShippingInformationManagement.php +++ b/app/code/Magento/Checkout/Model/ShippingInformationManagement.php @@ -144,6 +144,7 @@ class ShippingInformationManagement implements \Magento\Checkout\Api\ShippingInf /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); + $address->setLimitCarrier($carrierCode); $quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode); $this->validateQuote($quote); $quote->setIsMultiShipping(false); diff --git a/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php index 8da67a1fcb71512dd218a2c62d51b7922bb36c25..f256d8edefd1c9b2bd0dc41c838293cf4b9dfa32 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php @@ -5,8 +5,9 @@ */ namespace Magento\Checkout\Test\Unit\Model; -use Magento\Framework\Exception\CouldNotSaveException; - +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase { /** @@ -34,6 +35,11 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase */ private $loggerMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $cartRepositoryMock; + protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -46,7 +52,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $this->cartManagementMock = $this->getMock(\Magento\Quote\Api\CartManagementInterface::class); $this->loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class); - + $this->cartRepositoryMock = $this->getMockBuilder(\Magento\Quote\Api\CartRepositoryInterface::class)->getMock(); $this->model = $objectManager->getObject( \Magento\Checkout\Model\PaymentInformationManagement::class, [ @@ -56,6 +62,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ] ); $objectManager->setBackwardCompatibleProperty($this->model, 'logger', $this->loggerMock); + $objectManager->setBackwardCompatibleProperty($this->model, 'cartRepository', $this->cartRepositoryMock); } public function testSavePaymentInformationAndPlaceOrder() @@ -65,9 +72,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $this->billingAddressManagementMock->expects($this->once()) - ->method('assign') - ->with($cartId, $billingAddressMock); + $this->getMockForAssignBillingAddress($cartId, $billingAddressMock); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId); @@ -87,9 +92,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $this->billingAddressManagementMock->expects($this->once()) - ->method('assign') - ->with($cartId, $billingAddressMock); + $this->getMockForAssignBillingAddress($cartId, $billingAddressMock); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $exception = new \Exception(__('DB exception')); $this->loggerMock->expects($this->once())->method('critical'); @@ -104,7 +107,6 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $orderId = 200; $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); - $this->billingAddressManagementMock->expects($this->never())->method('assign'); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId); @@ -120,9 +122,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $this->billingAddressManagementMock->expects($this->once()) - ->method('assign') - ->with($cartId, $billingAddressMock); + $this->getMockForAssignBillingAddress($cartId, $billingAddressMock); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock, $billingAddressMock)); @@ -133,7 +133,6 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $cartId = 100; $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); - $this->billingAddressManagementMock->expects($this->never())->method('assign'); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock)); @@ -149,9 +148,8 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $this->billingAddressManagementMock->expects($this->once()) - ->method('assign') - ->with($cartId, $billingAddressMock); + $this->getMockForAssignBillingAddress($cartId, $billingAddressMock); + $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $phrase = new \Magento\Framework\Phrase(__('DB exception')); $exception = new \Magento\Framework\Exception\LocalizedException($phrase); @@ -160,4 +158,31 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase $this->model->savePaymentInformationAndPlaceOrder($cartId, $paymentMock, $billingAddressMock); } + + /** + * @param int $cartId + * @param \PHPUnit_Framework_MockObject_MockObject $billingAddressMock + */ + private function getMockForAssignBillingAddress($cartId, $billingAddressMock) + { + $billingAddressId = 1; + $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); + $quoteBillingAddress = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false); + $quoteShippingAddress = $this->getMock( + \Magento\Quote\Model\Quote\Address::class, + ['setLimitCarrier', 'getShippingMethod'], + [], + '', + false + ); + $this->cartRepositoryMock->expects($this->any())->method('getActive')->with($cartId)->willReturn($quoteMock); + $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($quoteBillingAddress); + $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($quoteShippingAddress); + $quoteBillingAddress->expects($this->once())->method('getId')->willReturn($billingAddressId); + $quoteMock->expects($this->once())->method('removeAddress')->with($billingAddressId); + $quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddressMock); + $quoteMock->expects($this->once())->method('setDataChanges')->willReturnSelf(); + $quoteShippingAddress->expects($this->any())->method('getShippingMethod')->willReturn('flatrate_flatrate'); + $quoteShippingAddress->expects($this->once())->method('setLimitCarrier')->with('flatrate')->willReturnSelf(); + } } diff --git a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php index 402a0c8228356a7ae8a148d7626e06bb5dc15a27..751bcee6db2a9fd6e2d15405c57f899a2d7ad972 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php @@ -109,7 +109,8 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase 'importCustomerAddressData', 'save', 'getShippingRateByCode', - 'getShippingMethod' + 'getShippingMethod', + 'setLimitCarrier' ], [], '', @@ -208,7 +209,7 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase private function setShippingAssignmentsMocks($shippingMethod) { $this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null); - + $this->shippingAddressMock->expects($this->once())->method('setLimitCarrier'); $this->cartExtensionMock = $this->getMock( \Magento\Quote\Api\Data\CartExtension::class, ['getShippingAssignments', 'setShippingAssignments'], diff --git a/app/code/Magento/Quote/Model/CustomerManagement.php b/app/code/Magento/Quote/Model/CustomerManagement.php index b796ebe9d0db4c0305c9e1d9c8e09838540ba820..04707e152674808b45c72c695861bd11b42cf13a 100644 --- a/app/code/Magento/Quote/Model/CustomerManagement.php +++ b/app/code/Magento/Quote/Model/CustomerManagement.php @@ -62,8 +62,6 @@ class CustomerManagement $quote->getPasswordHash() ); $quote->setCustomer($customer); - } else { - $this->customerRepository->save($customer); } if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) { $quote->getBillingAddress()->importCustomerAddressData( diff --git a/app/code/Magento/Quote/Test/Unit/Model/CustomerManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/CustomerManagementTest.php index 600bf1723a5c091a7879c3c1eb706c261f197c18..a1caac3473ccb3a352af6be8e64e36c4c6061cf3 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/CustomerManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/CustomerManagementTest.php @@ -158,4 +158,34 @@ class CustomerManagementTest extends \PHPUnit_Framework_TestCase ->willReturn($this->customerMock); $this->customerManagement->populateCustomerInfo($this->quoteMock); } + + public function testPopulateCustomerInfoForExistingCustomer() + { + $this->quoteMock->expects($this->once()) + ->method('getCustomer') + ->willReturn($this->customerMock); + $this->customerMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn(1); + $this->customerMock->expects($this->atLeastOnce()) + ->method('getDefaultBilling') + ->willReturn(100500); + $this->quoteMock->expects($this->atLeastOnce()) + ->method('getBillingAddress') + ->willReturn($this->quoteAddressMock); + $this->quoteMock->expects($this->atLeastOnce()) + ->method('getShippingAddress') + ->willReturn($this->quoteAddressMock); + $this->quoteAddressMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn(null); + $this->customerAddressRepositoryMock->expects($this->atLeastOnce()) + ->method('getById') + ->with(100500) + ->willReturn($this->customerAddressMock); + $this->quoteAddressMock->expects($this->atLeastOnce()) + ->method('importCustomerAddressData') + ->willReturnSelf(); + $this->customerManagement->populateCustomerInfo($this->quoteMock); + } } diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/RegisterCustomerFrontendEntityTest.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/RegisterCustomerFrontendEntityTest.xml index 96e78f58d78c8402a133184b633614e4e4fd20c7..43b4a251edd1b5a97d68d458b7203bd4435d69e0 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/RegisterCustomerFrontendEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/RegisterCustomerFrontendEntityTest.xml @@ -32,7 +32,7 @@ <constraint name="Magento\Newsletter\Test\Constraint\AssertCustomerIsSubscribedToNewsletter" /> </variation> <variation name="RegisterCustomerFrontendEntityTestVariation3" summary="Register Customer" ticketId="MAGETWO-12394"> - <data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test</data> + <data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test, stable:no</data> <data name="customer/data/firstname" xsi:type="string">john</data> <data name="customer/data/lastname" xsi:type="string">doe</data> <data name="customer/data/email" xsi:type="string">johndoe%isolation%@example.com</data> diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/ko/bind/datepicker.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/ko/bind/datepicker.test.js index e5f90863ec63071f191b82b0df7fdbba0ac411fa..3e99c1c454cf4b2261d99e3623f365570684a1e3 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/ko/bind/datepicker.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/ko/bind/datepicker.test.js @@ -1,5 +1,5 @@ /** - * Copyright © 2016 Magento. All rights reserved. + * Copyright © 2017 Magento. All rights reserved. * See COPYING.txt for license details. */ @@ -18,21 +18,23 @@ define([ config; beforeEach(function () { - element = $('<input />'); + element = $('<input />'); observable = ko.observable(); config = { - options : { + options: { dateFormat: 'M/d/yy', - 'storeLocale': 'en_US', - 'timeFormat': 'h:mm: a' + storeLocale: 'en_US', + timeFormat: 'h:mm: a' }, - storage:ko.observable(moment().format('MM/DD/YYYY')) + storage: observable }; $(document.body).append(element); - ko.applyBindingsToNode(element[0], { datepicker: config }); + ko.applyBindingsToNode(element[0], { + datepicker: config + }); }); afterEach(function () { @@ -40,20 +42,16 @@ define([ }); it('writes picked date\'s value to assigned observable', function () { - var todayDate, - momentFormat, - result, - inputFormat; - - inputFormat = 'M/d/yy'; + var todayDate, momentFormat, result, + inputFormat = 'M/d/yy'; momentFormat = utils.convertToMomentFormat(inputFormat); + todayDate = moment().format(momentFormat); - todayDate = moment().format(momentFormat); - - result = $('input:last').val(); + element.datepicker('setTimezoneDate').blur().trigger('change'); + result = moment(observable()).format(momentFormat); expect(todayDate).toEqual(result); }); }); -}); \ No newline at end of file +});