Skip to content

Commit a4d063a

Browse files
author
Tang, Yu(ytang1)
committed
Merge pull request #187 from magento-fearless-kiwis/FearlessKiwis-MAGETWO-45566-Credit-Memo-Divide-By-Zero
[FearlessKiwis] MAGETWO-45566 credit memo divide by zero
2 parents 95faca4 + 45009c1 commit a4d063a

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Total/Discount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
2525
* Calculate how much shipping discount should be applied
2626
* basing on how much shipping should be refunded.
2727
*/
28-
$baseShippingAmount = $creditmemo->getBaseShippingAmount();
28+
$baseShippingAmount = (float)$creditmemo->getBaseShippingAmount();
2929
if ($baseShippingAmount) {
3030
$baseShippingDiscount = $baseShippingAmount *
3131
$order->getBaseShippingDiscountAmount() /

app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/DiscountTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,71 @@ public function testCollect()
143143
);
144144
$this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
145145
}
146+
147+
public function testCollectZeroShipping()
148+
{
149+
$this->creditmemoMock->expects($this->exactly(2))
150+
->method('setDiscountAmount')
151+
->willReturnSelf();
152+
$this->creditmemoMock->expects($this->exactly(2))
153+
->method('setBaseDiscountAmount')
154+
->willReturnSelf();
155+
$this->creditmemoMock->expects($this->once())
156+
->method('getOrder')
157+
->willReturn($this->orderMock);
158+
$this->creditmemoMock->expects($this->once())
159+
->method('getBaseShippingAmount')
160+
->willReturn('0.0000');
161+
$this->orderMock->expects($this->never())
162+
->method('getBaseShippingDiscountAmount');
163+
$this->orderMock->expects($this->never())
164+
->method('getBaseShippingAmount');
165+
$this->orderMock->expects($this->never())
166+
->method('getShippingAmount');
167+
$this->creditmemoMock->expects($this->once())
168+
->method('getAllItems')
169+
->willReturn([$this->creditmemoItemMock]);
170+
$this->creditmemoItemMock->expects($this->atLeastOnce())
171+
->method('getOrderItem')
172+
->willReturn($this->orderItemMock);
173+
$this->orderItemMock->expects($this->once())
174+
->method('isDummy')
175+
->willReturn(false);
176+
$this->orderItemMock->expects($this->once())
177+
->method('getDiscountInvoiced')
178+
->willReturn(1);
179+
$this->orderItemMock->expects($this->once())
180+
->method('getBaseDiscountInvoiced')
181+
->willReturn(1);
182+
$this->orderItemMock->expects($this->once())
183+
->method('getQtyInvoiced')
184+
->willReturn(1);
185+
$this->orderItemMock->expects($this->once())
186+
->method('getDiscountRefunded')
187+
->willReturn(1);
188+
$this->orderItemMock->expects($this->once())
189+
->method('getQtyRefunded')
190+
->willReturn(0);
191+
$this->creditmemoItemMock->expects($this->once())
192+
->method('isLast')
193+
->willReturn(false);
194+
$this->creditmemoItemMock->expects($this->atLeastOnce())
195+
->method('getQty')
196+
->willReturn(1);
197+
$this->creditmemoItemMock->expects($this->exactly(1))
198+
->method('setDiscountAmount')
199+
->willReturnSelf();
200+
$this->creditmemoItemMock->expects($this->exactly(1))
201+
->method('setBaseDiscountAmount')
202+
->willReturnSelf();
203+
$this->creditmemoMock->expects($this->exactly(2))
204+
->method('roundPrice')
205+
->willReturnMap(
206+
[
207+
[1, 'regular', true, 1],
208+
[1, 'base', true, 1]
209+
]
210+
);
211+
$this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
212+
}
146213
}

0 commit comments

Comments
 (0)