Skip to content

Commit 002b0dc

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-39108' into BUGS
2 parents 2a834a3 + bee1eb0 commit 002b0dc

File tree

2 files changed

+150
-13
lines changed

2 files changed

+150
-13
lines changed

app/code/Magento/Quote/Model/Quote/Item/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function prepare(Item $item, Object $request, Product $candidate)
9494
/**
9595
* We specify qty after we know about parent (for stock)
9696
*/
97-
if ($request->getResetCount()) {
97+
if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) {
9898
$item->setData(CartItemInterface::KEY_QTY, 0);
9999
}
100100
$item->addQty($candidate->getCartQty());

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php

Lines changed: 149 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ protected function setUp()
7272

7373
$this->itemMock = $this->getMock(
7474
'Magento\Quote\Model\Quote\Item',
75-
['getId', 'setOptions', '__wakeup', 'setProduct', 'addQty', 'setCustomPrice', 'setOriginalCustomPrice'],
75+
[
76+
'getId',
77+
'setOptions',
78+
'__wakeup',
79+
'setProduct',
80+
'addQty',
81+
'setCustomPrice',
82+
'setOriginalCustomPrice',
83+
'setData'
84+
],
7685
[],
7786
'',
7887
false
@@ -109,7 +118,7 @@ protected function setUp()
109118

110119
$this->productMock = $this->getMock(
111120
'Magento\Catalog\Model\Product',
112-
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty'],
121+
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent'],
113122
[],
114123
'',
115124
false
@@ -148,8 +157,12 @@ public function testInitWithQtyModification()
148157
->will($this->returnValue($itemId));
149158
$this->itemMock->expects($this->any())
150159
->method('setData')
151-
->with($this->equalTo('qty'), $this->equalTo(0));
152-
160+
->willReturnMap(
161+
[
162+
['store_id', $storeId],
163+
['qty', 0],
164+
]
165+
);
153166

154167
$this->storeMock->expects($this->any())
155168
->method('getId')
@@ -177,15 +190,20 @@ public function testInitWithoutModification()
177190
->method('getParentProductId')
178191
->will($this->returnValue(true));
179192

180-
181193
$this->itemMock->expects($this->never())->method('setOptions');
182194
$this->itemMock->expects($this->never())->method('setProduct');
183195

184196
$this->itemMock->expects($this->any())
185197
->method('getId')
186198
->will($this->returnValue($itemId));
187199

188-
$this->itemMock->expects($this->never())->method('setData');
200+
$this->itemMock->expects($this->any())
201+
->method('setData')
202+
->willReturnMap(
203+
[
204+
['store_id', $storeId],
205+
]
206+
);
189207

190208
$this->storeMock->expects($this->any())
191209
->method('getId')
@@ -222,7 +240,13 @@ public function testInitWithoutModificationAdminhtmlAreaCode()
222240
->method('getId')
223241
->will($this->returnValue($itemId));
224242

225-
$this->itemMock->expects($this->never())->method('setData');
243+
$this->itemMock->expects($this->any())
244+
->method('setData')
245+
->willReturnMap(
246+
[
247+
['store_id', $storeId],
248+
]
249+
);
226250

227251
$this->storeMock->expects($this->any())
228252
->method('getId')
@@ -238,58 +262,171 @@ public function testPrepare()
238262
{
239263
$qty = 3000000000;
240264
$customPrice = 400000000;
265+
$itemId = 1;
266+
$requestItemId = 1;
241267

242268
$this->productMock->expects($this->any())
243269
->method('getCartQty')
244270
->will($this->returnValue($qty));
271+
$this->productMock->expects($this->any())
272+
->method('getStickWithinParent')
273+
->will($this->returnValue(false));
245274

246-
$this->itemMock->expects($this->any())
275+
$this->itemMock->expects($this->once())
247276
->method('addQty')
248277
->with($qty);
278+
$this->itemMock->expects($this->any())
279+
->method('getId')
280+
->will($this->returnValue($itemId));
281+
$this->itemMock->expects($this->never())
282+
->method('setData');
249283

250284
$this->objectMock->expects($this->any())
251285
->method('getCustomPrice')
252286
->will($this->returnValue($customPrice));
287+
$this->objectMock->expects($this->any())
288+
->method('getResetCount')
289+
->will($this->returnValue(false));
290+
$this->objectMock->expects($this->any())
291+
->method('getId')
292+
->will($this->returnValue($requestItemId));
293+
294+
$this->itemMock->expects($this->once())
295+
->method('setCustomPrice')
296+
->will($this->returnValue($customPrice));
297+
$this->itemMock->expects($this->once())
298+
->method('setOriginalCustomPrice')
299+
->will($this->returnValue($customPrice));
253300

301+
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
302+
}
303+
304+
public function testPrepareWithResetCountAndStick()
305+
{
306+
$qty = 3000000000;
307+
$customPrice = 400000000;
308+
$itemId = 1;
309+
$requestItemId = 1;
310+
311+
$this->productMock->expects($this->any())
312+
->method('getCartQty')
313+
->will($this->returnValue($qty));
314+
$this->productMock->expects($this->any())
315+
->method('getStickWithinParent')
316+
->will($this->returnValue(true));
317+
318+
$this->itemMock->expects($this->once())
319+
->method('addQty')
320+
->with($qty);
254321
$this->itemMock->expects($this->any())
322+
->method('getId')
323+
->will($this->returnValue($itemId));
324+
$this->itemMock->expects($this->never())
325+
->method('setData');
326+
327+
$this->objectMock->expects($this->any())
328+
->method('getCustomPrice')
329+
->will($this->returnValue($customPrice));
330+
$this->objectMock->expects($this->any())
331+
->method('getResetCount')
332+
->will($this->returnValue(true));
333+
$this->objectMock->expects($this->any())
334+
->method('getId')
335+
->will($this->returnValue($requestItemId));
336+
337+
$this->itemMock->expects($this->once())
255338
->method('setCustomPrice')
256339
->will($this->returnValue($customPrice));
340+
$this->itemMock->expects($this->once())
341+
->method('setOriginalCustomPrice')
342+
->will($this->returnValue($customPrice));
343+
344+
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
345+
}
346+
347+
public function testPrepareWithResetCountAndNotStickAndOtherItemId()
348+
{
349+
$qty = 3000000000;
350+
$customPrice = 400000000;
351+
$itemId = 1;
352+
$requestItemId = 2;
353+
354+
$this->productMock->expects($this->any())
355+
->method('getCartQty')
356+
->will($this->returnValue($qty));
357+
$this->productMock->expects($this->any())
358+
->method('getStickWithinParent')
359+
->will($this->returnValue(false));
360+
361+
$this->itemMock->expects($this->once())
362+
->method('addQty')
363+
->with($qty);
257364
$this->itemMock->expects($this->any())
365+
->method('getId')
366+
->will($this->returnValue($itemId));
367+
$this->itemMock->expects($this->never())
368+
->method('setData');
369+
370+
$this->objectMock->expects($this->any())
371+
->method('getCustomPrice')
372+
->will($this->returnValue($customPrice));
373+
$this->objectMock->expects($this->any())
374+
->method('getResetCount')
375+
->will($this->returnValue(true));
376+
$this->objectMock->expects($this->any())
377+
->method('getId')
378+
->will($this->returnValue($requestItemId));
379+
380+
$this->itemMock->expects($this->once())
381+
->method('setCustomPrice')
382+
->will($this->returnValue($customPrice));
383+
$this->itemMock->expects($this->once())
258384
->method('setOriginalCustomPrice')
259385
->will($this->returnValue($customPrice));
260386

261387
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
262388
}
263389

264-
public function testPrepareResetCount()
390+
public function testPrepareWithResetCountAndNotStickAndSameItemId()
265391
{
266392
$qty = 3000000000;
267393
$customPrice = 400000000;
394+
$itemId = 1;
395+
$requestItemId = 1;
268396

269397
$this->objectMock->expects($this->any())
270398
->method('getResetCount')
271399
->will($this->returnValue(true));
272400

273401
$this->itemMock->expects($this->any())
402+
->method('getId')
403+
->will($this->returnValue($itemId));
404+
$this->itemMock->expects($this->once())
274405
->method('setData')
275406
->with(CartItemInterface::KEY_QTY, 0);
276407

277408
$this->productMock->expects($this->any())
278409
->method('getCartQty')
279410
->will($this->returnValue($qty));
411+
$this->productMock->expects($this->any())
412+
->method('getStickWithinParent')
413+
->will($this->returnValue(false));
280414

281-
$this->itemMock->expects($this->any())
415+
$this->itemMock->expects($this->once())
282416
->method('addQty')
283417
->with($qty);
284418

285419
$this->objectMock->expects($this->any())
286420
->method('getCustomPrice')
287421
->will($this->returnValue($customPrice));
422+
$this->objectMock->expects($this->any())
423+
->method('getId')
424+
->will($this->returnValue($requestItemId));
288425

289-
$this->itemMock->expects($this->any())
426+
$this->itemMock->expects($this->once())
290427
->method('setCustomPrice')
291428
->will($this->returnValue($customPrice));
292-
$this->itemMock->expects($this->any())
429+
$this->itemMock->expects($this->once())
293430
->method('setOriginalCustomPrice')
294431
->will($this->returnValue($customPrice));
295432

0 commit comments

Comments
 (0)