Skip to content

Commit 25d8fbf

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-50972' into MPI-BUGFIXES
2 parents 0645a43 + 5ed5ec0 commit 25d8fbf

File tree

6 files changed

+213
-24
lines changed

6 files changed

+213
-24
lines changed

app/code/Magento/Quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public function save(CartInterface $quote, ShippingAssignmentInterface $shipping
6868
{
6969
/** @var \Magento\Quote\Model\Quote $quote */
7070
foreach ($shippingAssignment->getItems() as $item) {
71-
if (!$quote->getItemById($item->getItemId())) {
71+
/** @var \Magento\Quote\Model\Quote\Item $item */
72+
if (!$quote->getItemById($item->getItemId()) && !$item->isDeleted()) {
7273
$this->cartItemPersister->save($quote, $item);
7374
}
7475
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public function get($cartId, array $sharedStoreIds = [])
101101
$quote = $this->loadQuote('load', 'cartId', $cartId, $sharedStoreIds);
102102
$this->getLoadHandler()->load($quote);
103103
$this->quotesById[$cartId] = $quote;
104-
$this->quotesByCustomerId[$quote->getCustomerId()] = $quote;
105104
}
106105
return $this->quotesById[$cartId];
107106
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Test\Unit\Model\Quote\ShippingAssignment;
7+
8+
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
9+
use Magento\Quote\Api\Data\ShippingInterface;
10+
use Magento\Quote\Model\Quote;
11+
use Magento\Quote\Model\ShippingAssignmentFactory;
12+
use Magento\Quote\Model\Quote\Item\CartItemPersister;
13+
use Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor;
14+
use Magento\Quote\Model\Quote\ShippingAssignment\ShippingProcessor;
15+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
16+
17+
/**
18+
* Class ShippingAssignmentProcessorTest
19+
*/
20+
class ShippingAssignmentProcessorTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @var ShippingAssignmentFactory|MockObject
24+
*/
25+
private $shippingAssignmentFactory;
26+
27+
/**
28+
* @var ShippingProcessor|MockObject
29+
*/
30+
private $shippingProcessor;
31+
32+
/**
33+
* @var CartItemPersister|MockObject
34+
*/
35+
private $cartItemPersister;
36+
37+
/**
38+
* @var ShippingAssignmentProcessor
39+
*/
40+
private $shippingAssignmentProcessor;
41+
42+
protected function setUp()
43+
{
44+
$this->shippingAssignmentFactory = $this->getMockBuilder(ShippingAssignmentFactory::class)
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$this->shippingProcessor = $this->getMockBuilder(ShippingProcessor::class)
49+
->disableOriginalConstructor()
50+
->getMock();
51+
52+
$this->cartItemPersister = $this->getMockBuilder(CartItemPersister::class)
53+
->disableOriginalConstructor()
54+
->getMock();
55+
56+
$this->shippingAssignmentProcessor = new ShippingAssignmentProcessor(
57+
$this->shippingAssignmentFactory,
58+
$this->shippingProcessor,
59+
$this->cartItemPersister
60+
);
61+
}
62+
63+
/**
64+
* Test saving shipping assignments with deleted cart items
65+
*
66+
* @covers \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor::save
67+
*/
68+
public function testSaveWithDeletedCartItems()
69+
{
70+
$shippingAssignment = $this->getMockForAbstractClass(ShippingAssignmentInterface::class);
71+
$shipping = $this->getMockForAbstractClass(ShippingInterface::class);
72+
$quoteId = 1;
73+
74+
$quote = $this->getMockBuilder(Quote::class)
75+
->disableOriginalConstructor()
76+
->getMock();
77+
$quoteItem = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)
78+
->disableOriginalConstructor()
79+
->getMock();
80+
$quoteItem->expects(static::once())
81+
->method('isDeleted')
82+
->willReturn(true);
83+
$quoteItem->expects(static::once())
84+
->method('getItemId')
85+
->willReturn($quoteId);
86+
87+
$quote->expects(static::once())
88+
->method('getItemById')
89+
->with($quoteId)
90+
->willReturn(null);
91+
92+
$shippingAssignment->expects(static::once())
93+
->method('getItems')
94+
->willReturn([$quoteItem]);
95+
$shippingAssignment->expects(static::once())
96+
->method('getShipping')
97+
->willReturn($shipping);
98+
99+
$this->cartItemPersister->expects(static::never())
100+
->method('save');
101+
102+
$this->shippingProcessor->expects(static::once())
103+
->method('save')
104+
->with($shipping, $quote);
105+
106+
$this->shippingAssignmentProcessor->save(
107+
$quote,
108+
$shippingAssignment
109+
);
110+
}
111+
}

app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
namespace Magento\Quote\Test\Unit\Model;
99

10-
use Magento\Quote\Api\CartRepositoryInterface;
11-
1210
use Magento\Framework\Api\SortOrder;
1311
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
12+
use Magento\Quote\Model\QuoteRepository\LoadHandler;
1413

14+
/**
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
*/
1517
class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
1618
{
1719
/**
@@ -54,6 +56,11 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
5456
*/
5557
private $extensionAttributesJoinProcessorMock;
5658

59+
/**
60+
* @var LoadHandler|\PHPUnit_Framework_MockObject_MockObject
61+
*/
62+
private $loadHandlerMock;
63+
5764
protected function setUp()
5865
{
5966
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -107,6 +114,12 @@ protected function setUp()
107114
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock
108115
]
109116
);
117+
118+
$this->loadHandlerMock = $this->getMock(LoadHandler::class, [], [], '', false);
119+
$reflection = new \ReflectionClass(get_class($this->model));
120+
$reflectionProperty = $reflection->getProperty('loadHandler');
121+
$reflectionProperty->setAccessible(true);
122+
$reflectionProperty->setValue($this->model, $this->loadHandlerMock);
110123
}
111124

112125
/**
@@ -132,21 +145,72 @@ public function testGetWithExceptionById()
132145

133146
public function testGet()
134147
{
135-
$this->markTestSkipped('MAGETWO-48531');
136148
$cartId = 15;
137149

138-
$this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
139-
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
140-
$this->storeMock->expects($this->once())->method('getId')->willReturn(1);
141-
$this->quoteMock->expects($this->never())->method('setSharedStoreIds');
142-
$this->quoteMock->expects($this->once())
150+
$this->quoteFactoryMock->expects(static::once())
151+
->method('create')
152+
->willReturn($this->quoteMock);
153+
$this->storeManagerMock->expects(static::once())
154+
->method('getStore')
155+
->willReturn($this->storeMock);
156+
$this->storeMock->expects(static::once())
157+
->method('getId')
158+
->willReturn(1);
159+
$this->quoteMock->expects(static::never())
160+
->method('setSharedStoreIds');
161+
$this->quoteMock->expects(static::once())
143162
->method('load')
144163
->with($cartId)
145164
->willReturn($this->storeMock);
146-
$this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
165+
$this->quoteMock->expects(static::once())
166+
->method('getId')
167+
->willReturn($cartId);
168+
$this->quoteMock->expects(static::never())
169+
->method('getCustomerId');
170+
$this->loadHandlerMock->expects(static::once())
171+
->method('load')
172+
->with($this->quoteMock);
173+
174+
static::assertEquals($this->quoteMock, $this->model->get($cartId));
175+
static::assertEquals($this->quoteMock, $this->model->get($cartId));
176+
}
177+
178+
public function testGetForCustomerAfterGet()
179+
{
180+
$cartId = 15;
181+
$customerId = 23;
182+
183+
$this->quoteFactoryMock->expects(static::exactly(2))
184+
->method('create')
185+
->willReturn($this->quoteMock);
186+
$this->storeManagerMock->expects(static::exactly(2))
187+
->method('getStore')
188+
->willReturn($this->storeMock);
189+
$this->storeMock->expects(static::exactly(2))
190+
->method('getId')
191+
->willReturn(1);
192+
$this->quoteMock->expects(static::never())
193+
->method('setSharedStoreIds');
194+
$this->quoteMock->expects(static::once())
195+
->method('load')
196+
->with($cartId)
197+
->willReturn($this->storeMock);
198+
$this->quoteMock->expects(static::once())
199+
->method('loadByCustomer')
200+
->with($customerId)
201+
->willReturn($this->storeMock);
202+
$this->quoteMock->expects(static::exactly(3))
203+
->method('getId')
204+
->willReturn($cartId);
205+
$this->quoteMock->expects(static::any())
206+
->method('getCustomerId')
207+
->willReturn($customerId);
208+
$this->loadHandlerMock->expects(static::exactly(2))
209+
->method('load')
210+
->with($this->quoteMock);
147211

148-
$this->assertEquals($this->quoteMock, $this->model->get($cartId));
149-
$this->assertEquals($this->quoteMock, $this->model->get($cartId));
212+
static::assertEquals($this->quoteMock, $this->model->get($cartId));
213+
static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
150214
}
151215

152216
public function testGetWithSharedStoreIds()
@@ -174,22 +238,34 @@ public function testGetWithSharedStoreIds()
174238

175239
public function testGetForCustomer()
176240
{
177-
$this->markTestSkipped('MAGETWO-48531');
178241
$cartId = 17;
179242
$customerId = 23;
180243

181-
$this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
182-
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
183-
$this->storeMock->expects($this->once())->method('getId')->willReturn(1);
184-
$this->quoteMock->expects($this->never())->method('setSharedStoreIds');
185-
$this->quoteMock->expects($this->once())
244+
$this->quoteFactoryMock->expects(static::once())
245+
->method('create')
246+
->willReturn($this->quoteMock);
247+
$this->storeManagerMock->expects(static::once())
248+
->method('getStore')
249+
->willReturn($this->storeMock);
250+
$this->storeMock->expects(static::once())
251+
->method('getId')
252+
->willReturn(1);
253+
$this->quoteMock->expects(static::never())
254+
->method('setSharedStoreIds');
255+
$this->quoteMock->expects(static::once())
186256
->method('loadByCustomer')
187257
->with($customerId)
188258
->willReturn($this->storeMock);
189-
$this->quoteMock->expects($this->exactly(2))->method('getId')->willReturn($cartId);
259+
$this->quoteMock->expects(static::exactly(2))
260+
->method('getId')
261+
->willReturn($cartId);
262+
263+
$this->loadHandlerMock->expects(static::once())
264+
->method('load')
265+
->with($this->quoteMock);
190266

191-
$this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
192-
$this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
267+
static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
268+
static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
193269
}
194270

195271
/**

app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ protected function _processActionData($action = null)
243243
$removeFrom = (string)$this->getRequest()->getPost('from');
244244
if ($removeItemId && $removeFrom) {
245245
$this->_getOrderCreateModel()->removeItem($removeItemId, $removeFrom);
246+
$this->_getOrderCreateModel()->recollectCart();
246247
}
247248

248249
/**

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,8 @@ public function applySidebarData($data)
931931
$this->quoteRepository->save($this->getCustomerCart());
932932
}
933933

934+
$this->recollectCart();
935+
934936
return $this;
935937
}
936938

@@ -951,8 +953,7 @@ public function removeItem($itemId, $from)
951953
$cart = $this->getCustomerCart();
952954
if ($cart) {
953955
$cart->removeItem($itemId);
954-
$cart->collectTotals();
955-
$this->quoteRepository->save($cart);
956+
$this->_needCollectCart = true;
956957
}
957958
break;
958959
case 'wishlist':

0 commit comments

Comments
 (0)