Skip to content

Commit d70ff4b

Browse files
MAGETWO-95773: Credit memo is created instead of returning error via invoice refund API for Bundle product
- fix unit and static tests
1 parent 052d0cc commit d70ff4b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Item/Validation/CreationQuantityValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CreationQuantityValidator implements ValidatorInterface
3030

3131
/**
3232
* ItemCreationQuantityValidator constructor.
33+
*
3334
* @param OrderItemRepositoryInterface $orderItemRepository
3435
* @param mixed $context
3536
*/
@@ -65,6 +66,8 @@ public function validate($entity)
6566
}
6667

6768
/**
69+
* Check the quantity to refund is greater than the unrefunded quantity
70+
*
6871
* @param Item $orderItem
6972
* @param int $qty
7073
* @return bool
@@ -75,6 +78,8 @@ private function isQtyAvailable(Item $orderItem, $qty)
7578
}
7679

7780
/**
81+
* Check to see if Item is part of the order
82+
*
7883
* @param OrderItemInterface $orderItem
7984
* @return bool
8085
*/

app/code/Magento/Sales/Model/Order/ItemRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function __construct(
9595
}
9696

9797
/**
98-
* load entity
98+
* Load entity
9999
*
100100
* @param int $id
101101
* @return OrderItemInterface
@@ -230,7 +230,7 @@ private function addParentItem(OrderItemInterface $orderItem)
230230
$orderItem->setParentItem($this->get($parentId));
231231
} else {
232232
foreach ($orderItem->getOrder()->getAllItems() as $item) {
233-
if($item->getParentItemId() === $orderItem->getItemId()) {
233+
if ($item->getParentItemId() === $orderItem->getItemId()) {
234234
$item->setParentItem($orderItem);
235235
}
236236
}

app/code/Magento/Sales/Test/Unit/Model/Order/ItemRepositoryTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,27 @@ public function testGet()
156156
$productOption = $this->getProductOptionMock();
157157
$orderItemMock = $this->getOrderMock($productType, $productOption);
158158

159+
$orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
160+
$orderMock->expects($this->once())
161+
->method('getAllItems')
162+
->willReturn([$orderItemMock]);
163+
159164
$orderItemMock->expects($this->once())
160165
->method('load')
161166
->with($orderItemId)
162167
->willReturn($orderItemMock);
163-
$orderItemMock->expects($this->once())
168+
$orderItemMock->expects($this->exactly(2))
164169
->method('getItemId')
165170
->willReturn($orderItemId);
171+
$orderItemMock->expects($this->once())
172+
->method('getOrder')
173+
->willReturn($orderMock);
166174

167175
$this->metadata->expects($this->once())
168176
->method('getNewInstance')
169177
->willReturn($orderItemMock);
170178

179+
171180
$model = $this->getModel($orderItemMock, $productType);
172181
$this->assertSame($orderItemMock, $model->get($orderItemId));
173182

@@ -213,11 +222,17 @@ public function testDeleteById()
213222
$orderItemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
214223
->disableOriginalConstructor()
215224
->getMock();
225+
226+
$orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
227+
$orderMock->expects($this->once())
228+
->method('getAllItems')
229+
->willReturn([$orderItemMock]);
230+
216231
$orderItemMock->expects($this->once())
217232
->method('load')
218233
->with($orderItemId)
219234
->willReturn($orderItemMock);
220-
$orderItemMock->expects($this->once())
235+
$orderItemMock->expects($this->exactly(2))
221236
->method('getItemId')
222237
->willReturn($orderItemId);
223238
$orderItemMock->expects($this->once())
@@ -226,6 +241,9 @@ public function testDeleteById()
226241
$orderItemMock->expects($this->once())
227242
->method('getBuyRequest')
228243
->willReturn($requestMock);
244+
$orderItemMock->expects($this->once())
245+
->method('getOrder')
246+
->willReturn($orderMock);
229247

230248
$orderItemResourceMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class)
231249
->disableOriginalConstructor()

0 commit comments

Comments
 (0)