Skip to content

Commit 77950cf

Browse files
committed
Merge branch 'develop' of https://github.corp.magento.com/magento2/magento2ce into develop
2 parents 14cd2fe + fc9cb7e commit 77950cf

File tree

8 files changed

+81
-35
lines changed

8 files changed

+81
-35
lines changed

app/code/Magento/Backend/Model/Session/Quote.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Customer\Api\CustomerRepositoryInterface;
99
use Magento\Customer\Api\GroupManagementInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Quote\Api\CartManagementInterface;
1012

1113
/**
1214
* Adminhtml quote session
@@ -79,6 +81,11 @@ class Quote extends \Magento\Framework\Session\SessionManager
7981
*/
8082
protected $quoteFactory;
8183

84+
/**
85+
* @var \Magento\Quote\Api\CartManagementInterface;
86+
*/
87+
private $cartManagement;
88+
8289
/**
8390
* @param \Magento\Framework\App\Request\Http $request
8491
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
@@ -143,15 +150,15 @@ public function __construct(
143150
*/
144151
public function getQuote()
145152
{
153+
$cartManagement = $this->getCartManagement();
154+
146155
if ($this->_quote === null) {
147-
$this->_quote = $this->quoteFactory->create();
148156
if ($this->getStoreId()) {
149157
if (!$this->getQuoteId()) {
150-
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId())
151-
->setIsActive(false)
152-
->setStoreId($this->getStoreId());
153-
$this->quoteRepository->save($this->_quote);
154-
$this->setQuoteId($this->_quote->getId());
158+
$this->setQuoteId($cartManagement->createEmptyCart());
159+
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
160+
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId());
161+
$this->_quote->setIsActive(false);
155162
} else {
156163
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
157164
$this->_quote->setStoreId($this->getStoreId());
@@ -169,6 +176,18 @@ public function getQuote()
169176
return $this->_quote;
170177
}
171178

179+
/**
180+
* @return CartManagementInterface
181+
* @deprecated
182+
*/
183+
private function getCartManagement()
184+
{
185+
if ($this->cartManagement === null) {
186+
$this->cartManagement = ObjectManager::getInstance()->get(CartManagementInterface::class);
187+
}
188+
return $this->cartManagement;
189+
}
190+
172191
/**
173192
* Retrieve store model object
174193
*

app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
9292
*/
9393
protected $quoteFactoryMock;
9494

95+
/**
96+
* @var \PHPUnit_Framework_MockObject_MockObject
97+
*/
98+
protected $cartManagementMock;
99+
95100
/**
96101
* Set up
97102
*
@@ -197,9 +202,16 @@ protected function setUp()
197202
);
198203

199204
$this->quoteFactoryMock = $this->getMock('\Magento\Quote\Model\QuoteFactory', ['create'], [], '', false);
205+
$this->cartManagementMock = $this->getMock(
206+
\Magento\Quote\Api\CartManagementInterface::class,
207+
[],
208+
[],
209+
'',
210+
false
211+
);
200212

201213
$this->quote = $this->getMock(
202-
'Magento\Backend\Model\Session\Quote',
214+
\Magento\Backend\Model\Session\Quote::class,
203215
['getStoreId', 'getQuoteId', 'setQuoteId', 'hasCustomerId', 'getCustomerId'],
204216
[
205217
'request' => $this->requestMock,
@@ -217,10 +229,12 @@ protected function setUp()
217229
'storeManager' => $this->storeManagerMock,
218230
'groupManagement' => $this->groupManagementMock,
219231
'quoteFactory' => $this->quoteFactoryMock
220-
],
221-
'',
222-
true
232+
]
223233
);
234+
235+
$this->prepareObjectManager([
236+
[\Magento\Quote\Api\CartManagementInterface::class, $this->cartManagementMock]
237+
]);
224238
}
225239

226240
/**
@@ -235,6 +249,8 @@ public function testGetQuoteWithoutQuoteId()
235249
$customerId = 66;
236250
$customerGroupId = 77;
237251

252+
$this->cartManagementMock->expects($this->once())->method('createEmptyCart')->willReturn($quoteId);
253+
238254
$this->quote->expects($this->any())
239255
->method('getQuoteId')
240256
->will($this->returnValue(null));
@@ -271,7 +287,6 @@ public function testGetQuoteWithoutQuoteId()
271287
'setStoreId',
272288
'setCustomerGroupId',
273289
'setIsActive',
274-
'getId',
275290
'assignCustomer',
276291
'setIgnoreOldQty',
277292
'setIsSuperMode',
@@ -281,9 +296,7 @@ public function testGetQuoteWithoutQuoteId()
281296
'',
282297
false
283298
);
284-
$quoteMock->expects($this->once())
285-
->method('setStoreId')
286-
->with($storeId);
299+
$this->quoteRepositoryMock->expects($this->once())->method('get')->willReturn($quoteMock);
287300
$quoteMock->expects($this->once())
288301
->method('setCustomerGroupId')
289302
->with($customerGroupId)
@@ -292,9 +305,6 @@ public function testGetQuoteWithoutQuoteId()
292305
->method('setIsActive')
293306
->with(false)
294307
->will($this->returnSelf());
295-
$quoteMock->expects($this->once())
296-
->method('getId')
297-
->will($this->returnValue($quoteId));
298308
$quoteMock->expects($this->once())
299309
->method('assignCustomer')
300310
->with($dataCustomerMock);
@@ -305,13 +315,6 @@ public function testGetQuoteWithoutQuoteId()
305315
->method('setIsSuperMode')
306316
->with(true);
307317

308-
$this->quoteFactoryMock->expects($this->once())
309-
->method('create')
310-
->will($this->returnValue($quoteMock));
311-
$this->quoteRepositoryMock->expects($this->once())
312-
->method('save')
313-
->with($quoteMock);
314-
315318
$this->assertEquals($quoteMock, $this->quote->getQuote());
316319
}
317320

@@ -380,9 +383,6 @@ public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expected
380383
->method('getCustomerId')
381384
->will($this->returnValue($quoteCustomerId));
382385

383-
$this->quoteFactoryMock->expects($this->once())
384-
->method('create')
385-
->will($this->returnValue($quoteMock));
386386
$this->quoteRepositoryMock->expects($this->once())
387387
->method('get')
388388
->with($quoteId)
@@ -401,4 +401,19 @@ public function getQuoteDataProvider()
401401
'customer ids same' => [66, 66, 'never'],
402402
];
403403
}
404+
405+
/**
406+
* @param array $map
407+
* @deprecated
408+
*/
409+
private function prepareObjectManager($map)
410+
{
411+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
412+
$objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf();
413+
$objectManagerMock->expects($this->any())->method('get')->will($this->returnValueMap($map));
414+
$reflectionClass = new \ReflectionClass('Magento\Framework\App\ObjectManager');
415+
$reflectionProperty = $reflectionClass->getProperty('_instance');
416+
$reflectionProperty->setAccessible(true);
417+
$reflectionProperty->setValue($objectManagerMock);
418+
}
404419
}

app/code/Magento/Quote/Model/QuoteAddressValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function validate(\Magento\Quote\Api\Data\AddressInterface $addressData)
8181
}, $this->customerRepository->getById($addressData->getCustomerId())->getAddresses());
8282
if (!in_array($addressData->getCustomerAddressId(), $applicableAddressIds)) {
8383
throw new \Magento\Framework\Exception\NoSuchEntityException(
84-
__('Invalid address id %1', $addressData->getCustomerAddressId())
84+
__('Invalid customer address id %1', $addressData->getCustomerAddressId())
8585
);
8686
}
8787
}

app/code/Magento/Quote/Model/QuoteRepository/SaveHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function save(CartInterface $quote)
6262
/** @var \Magento\Quote\Model\Quote $quote */
6363
// Quote Item processing
6464
$items = $quote->getItems();
65-
if ($items && $quote->getIsActive()) {
65+
if ($items) {
6666
foreach ($items as $item) {
6767
/** @var \Magento\Quote\Model\Quote\Item $item */
6868
if (!$item->isDeleted()) {
@@ -73,7 +73,7 @@ public function save(CartInterface $quote)
7373

7474
// Billing Address processing
7575
$billingAddress = $quote->getBillingAddress();
76-
if ($billingAddress && $quote->getIsActive()) {
76+
if ($billingAddress) {
7777
$this->billingAddressPersister->save($quote, $billingAddress);
7878
}
7979

app/code/Magento/Quote/Test/Unit/Model/QuoteRepository/SaveHandlerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public function testSaveForVirtualQuote()
120120
->willReturn($this->itemMock);
121121
$this->quoteMock->expects($this->once())->method('setLastAddedItem')->with($this->itemMock);
122122
$this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($this->billingAddressMock);
123-
$this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(true);
124123
$this->billingAddressPersister
125124
->expects($this->once())
126125
->method('save')

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Shipping/Method.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class Method extends Block
3636
*/
3737
public function selectShippingMethod(array $shippingMethod)
3838
{
39-
$this->_rootElement->find($this->shippingMethodsLink)->click();
39+
if ($this->_rootElement->find($this->shippingMethodsLink)->isVisible()) {
40+
$this->_rootElement->find($this->shippingMethodsLink)->click();
41+
}
4042
$selector = sprintf(
4143
$this->shippingMethod,
4244
$shippingMethod['shipping_service'],

dev/tests/integration/testsuite/Magento/Customer/_files/customer_address.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Copyright © 2016 Magento. All rights reserved.
66
* See COPYING.txt for license details.
77
*/
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
89
/** @var \Magento\Customer\Model\Address $customerAddress */
9-
$customerAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
10-
->create('Magento\Customer\Model\Address');
10+
$customerAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
1111
$customerAddress->isObjectNew(true);
1212
$customerAddress->setData(
1313
[
@@ -24,5 +24,15 @@
2424
'parent_id' => 1,
2525
'region_id' => 1,
2626
]
27-
)->setCustomerId(1);
27+
);
2828
$customerAddress->save();
29+
30+
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
31+
$addressRepository = $objectManager->get(\Magento\Customer\Api\AddressRepositoryInterface::class);
32+
$customerAddress = $addressRepository->getById(1);
33+
$customerAddress->setCustomerId(1);
34+
$customerAddress = $addressRepository->save($customerAddress);
35+
36+
/** @var \Magento\Customer\Model\AddressRegistry $addressRegistry */
37+
$addressRegistry = $objectManager->get(\Magento\Customer\Model\AddressRegistry::class);
38+
$addressRegistry->remove($customerAddress->getId());

dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
1717
*/
1818
public function testSubmit()
1919
{
20+
$this->markTestSkipped('MAGETWO-50989');
2021
/**
2122
* Preconditions:
2223
* Load quote with Bundle product that has at least to child products

0 commit comments

Comments
 (0)