Skip to content
Snippets Groups Projects
Commit 9d56fc68 authored by vklymenko's avatar vklymenko
Browse files

Merge remote-tracking branch 'origin/develop' into Sprint55

parents 5a42ebf2 dd124b78
No related merge requests found
...@@ -14,6 +14,7 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor ...@@ -14,6 +14,7 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor
{ {
/** /**
* @var \Magento\Quote\Api\BillingAddressManagementInterface * @var \Magento\Quote\Api\BillingAddressManagementInterface
* @deprecated This call was substituted to eliminate extra quote::save call
*/ */
protected $billingAddressManagement; protected $billingAddressManagement;
...@@ -42,6 +43,11 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor ...@@ -42,6 +43,11 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor
*/ */
private $logger; private $logger;
/**
* @var \Magento\Quote\Api\CartRepositoryInterface
*/
private $cartRepository;
/** /**
* @param \Magento\Quote\Api\BillingAddressManagementInterface $billingAddressManagement * @param \Magento\Quote\Api\BillingAddressManagementInterface $billingAddressManagement
* @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement * @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
...@@ -99,7 +105,19 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor ...@@ -99,7 +105,19 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) { ) {
if ($billingAddress) { 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); $this->paymentMethodManagement->set($cartId, $paymentMethod);
return true; return true;
...@@ -130,4 +148,19 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor ...@@ -130,4 +148,19 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor
} }
return $this->logger; 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;
}
} }
...@@ -144,6 +144,7 @@ class ShippingInformationManagement implements \Magento\Checkout\Api\ShippingInf ...@@ -144,6 +144,7 @@ class ShippingInformationManagement implements \Magento\Checkout\Api\ShippingInf
/** @var \Magento\Quote\Model\Quote $quote */ /** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->getActive($cartId); $quote = $this->quoteRepository->getActive($cartId);
$address->setLimitCarrier($carrierCode);
$quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode); $quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode);
$this->validateQuote($quote); $this->validateQuote($quote);
$quote->setIsMultiShipping(false); $quote->setIsMultiShipping(false);
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
*/ */
namespace Magento\Checkout\Test\Unit\Model; namespace Magento\Checkout\Test\Unit\Model;
use Magento\Framework\Exception\CouldNotSaveException; /**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
...@@ -34,6 +35,11 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -34,6 +35,11 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
*/ */
private $loggerMock; private $loggerMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $cartRepositoryMock;
protected function setUp() protected function setUp()
{ {
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
...@@ -46,7 +52,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -46,7 +52,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$this->cartManagementMock = $this->getMock(\Magento\Quote\Api\CartManagementInterface::class); $this->cartManagementMock = $this->getMock(\Magento\Quote\Api\CartManagementInterface::class);
$this->loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class); $this->loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class);
$this->cartRepositoryMock = $this->getMockBuilder(\Magento\Quote\Api\CartRepositoryInterface::class)->getMock();
$this->model = $objectManager->getObject( $this->model = $objectManager->getObject(
\Magento\Checkout\Model\PaymentInformationManagement::class, \Magento\Checkout\Model\PaymentInformationManagement::class,
[ [
...@@ -56,6 +62,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -56,6 +62,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
] ]
); );
$objectManager->setBackwardCompatibleProperty($this->model, 'logger', $this->loggerMock); $objectManager->setBackwardCompatibleProperty($this->model, 'logger', $this->loggerMock);
$objectManager->setBackwardCompatibleProperty($this->model, 'cartRepository', $this->cartRepositoryMock);
} }
public function testSavePaymentInformationAndPlaceOrder() public function testSavePaymentInformationAndPlaceOrder()
...@@ -65,9 +72,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -65,9 +72,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
$this->billingAddressManagementMock->expects($this->once()) $this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
->method('assign')
->with($cartId, $billingAddressMock);
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
$this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId); $this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId);
...@@ -87,9 +92,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -87,9 +92,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
$this->billingAddressManagementMock->expects($this->once()) $this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
->method('assign')
->with($cartId, $billingAddressMock);
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
$exception = new \Exception(__('DB exception')); $exception = new \Exception(__('DB exception'));
$this->loggerMock->expects($this->once())->method('critical'); $this->loggerMock->expects($this->once())->method('critical');
...@@ -104,7 +107,6 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -104,7 +107,6 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$orderId = 200; $orderId = 200;
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $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->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
$this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId); $this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId);
...@@ -120,9 +122,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -120,9 +122,7 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
$this->billingAddressManagementMock->expects($this->once()) $this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
->method('assign')
->with($cartId, $billingAddressMock);
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
$this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock, $billingAddressMock)); $this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock, $billingAddressMock));
...@@ -133,7 +133,6 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -133,7 +133,6 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$cartId = 100; $cartId = 100;
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $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->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
$this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock)); $this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock));
...@@ -149,9 +148,8 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -149,9 +148,8 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class); $paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
$this->billingAddressManagementMock->expects($this->once()) $this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
->method('assign')
->with($cartId, $billingAddressMock);
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
$phrase = new \Magento\Framework\Phrase(__('DB exception')); $phrase = new \Magento\Framework\Phrase(__('DB exception'));
$exception = new \Magento\Framework\Exception\LocalizedException($phrase); $exception = new \Magento\Framework\Exception\LocalizedException($phrase);
...@@ -160,4 +158,31 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -160,4 +158,31 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
$this->model->savePaymentInformationAndPlaceOrder($cartId, $paymentMock, $billingAddressMock); $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();
}
} }
...@@ -109,7 +109,8 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -109,7 +109,8 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase
'importCustomerAddressData', 'importCustomerAddressData',
'save', 'save',
'getShippingRateByCode', 'getShippingRateByCode',
'getShippingMethod' 'getShippingMethod',
'setLimitCarrier'
], ],
[], [],
'', '',
...@@ -208,7 +209,7 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase ...@@ -208,7 +209,7 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase
private function setShippingAssignmentsMocks($shippingMethod) private function setShippingAssignmentsMocks($shippingMethod)
{ {
$this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null); $this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null);
$this->shippingAddressMock->expects($this->once())->method('setLimitCarrier');
$this->cartExtensionMock = $this->getMock( $this->cartExtensionMock = $this->getMock(
\Magento\Quote\Api\Data\CartExtension::class, \Magento\Quote\Api\Data\CartExtension::class,
['getShippingAssignments', 'setShippingAssignments'], ['getShippingAssignments', 'setShippingAssignments'],
......
...@@ -62,8 +62,6 @@ class CustomerManagement ...@@ -62,8 +62,6 @@ class CustomerManagement
$quote->getPasswordHash() $quote->getPasswordHash()
); );
$quote->setCustomer($customer); $quote->setCustomer($customer);
} else {
$this->customerRepository->save($customer);
} }
if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) { if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) {
$quote->getBillingAddress()->importCustomerAddressData( $quote->getBillingAddress()->importCustomerAddressData(
......
...@@ -158,4 +158,34 @@ class CustomerManagementTest extends \PHPUnit_Framework_TestCase ...@@ -158,4 +158,34 @@ class CustomerManagementTest extends \PHPUnit_Framework_TestCase
->willReturn($this->customerMock); ->willReturn($this->customerMock);
$this->customerManagement->populateCustomerInfo($this->quoteMock); $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);
}
} }
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<constraint name="Magento\Newsletter\Test\Constraint\AssertCustomerIsSubscribedToNewsletter" /> <constraint name="Magento\Newsletter\Test\Constraint\AssertCustomerIsSubscribedToNewsletter" />
</variation> </variation>
<variation name="RegisterCustomerFrontendEntityTestVariation3" summary="Register Customer" ticketId="MAGETWO-12394"> <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/firstname" xsi:type="string">john</data>
<data name="customer/data/lastname" xsi:type="string">doe</data> <data name="customer/data/lastname" xsi:type="string">doe</data>
<data name="customer/data/email" xsi:type="string">johndoe%isolation%@example.com</data> <data name="customer/data/email" xsi:type="string">johndoe%isolation%@example.com</data>
......
/** /**
* Copyright © 2016 Magento. All rights reserved. * Copyright © 2017 Magento. All rights reserved.
* See COPYING.txt for license details. * See COPYING.txt for license details.
*/ */
...@@ -18,21 +18,23 @@ define([ ...@@ -18,21 +18,23 @@ define([
config; config;
beforeEach(function () { beforeEach(function () {
element = $('<input />'); element = $('<input />');
observable = ko.observable(); observable = ko.observable();
config = { config = {
options : { options: {
dateFormat: 'M/d/yy', dateFormat: 'M/d/yy',
'storeLocale': 'en_US', storeLocale: 'en_US',
'timeFormat': 'h:mm: a' timeFormat: 'h:mm: a'
}, },
storage:ko.observable(moment().format('MM/DD/YYYY')) storage: observable
}; };
$(document.body).append(element); $(document.body).append(element);
ko.applyBindingsToNode(element[0], { datepicker: config }); ko.applyBindingsToNode(element[0], {
datepicker: config
});
}); });
afterEach(function () { afterEach(function () {
...@@ -40,20 +42,16 @@ define([ ...@@ -40,20 +42,16 @@ define([
}); });
it('writes picked date\'s value to assigned observable', function () { it('writes picked date\'s value to assigned observable', function () {
var todayDate, var todayDate, momentFormat, result,
momentFormat, inputFormat = 'M/d/yy';
result,
inputFormat;
inputFormat = 'M/d/yy';
momentFormat = utils.convertToMomentFormat(inputFormat); momentFormat = utils.convertToMomentFormat(inputFormat);
todayDate = moment().format(momentFormat);
todayDate = moment().format(momentFormat); element.datepicker('setTimezoneDate').blur().trigger('change');
result = moment(observable()).format(momentFormat);
result = $('input:last').val();
expect(todayDate).toEqual(result); expect(todayDate).toEqual(result);
}); });
}); });
}); });
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment