Skip to content

Commit 6325f35

Browse files
committed
Merge branch 'ACP2E-92' of https://github.com/magento-l3/magento2ce into ACP2E-92
2 parents 99d0520 + ef8b83b commit 6325f35

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Validation/QuantityValidator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Sales\Model\Order\Item;
1818
use Magento\Sales\Model\ValidatorInterface;
1919
use Magento\Sales\Api\Data\CreditmemoItemInterface;
20-
use \Magento\Framework\Phrase;
20+
use Magento\Framework\Phrase;
2121

2222
/**
2323
* Creditmemo QuantityValidator
@@ -107,22 +107,22 @@ public function validate($entity)
107107
private function isValidDecimalRefundQty($isQtyDecimal, float $itemQty): bool
108108
{
109109
if (!$isQtyDecimal && (floor($itemQty) !== $itemQty)) {
110-
return true;
110+
return false;
111111
}
112-
return false;
112+
return true;
113113
}
114114

115115
/**
116116
* Calculate total quantity.
117117
*
118118
* @param array $orderItemsById
119-
* @param Magento\Sales\Api\Data\CreditmemoItemInterface|mixed $item
119+
* @param CreditmemoItemInterface $item
120120
* @param array $invoiceQtysRefundLimits
121121
* @return Phrase|void
122122
*/
123123
private function validateTotalQuantityRefundable(
124124
array $orderItemsById,
125-
$item,
125+
CreditmemoItemInterface $item,
126126
array $invoiceQtysRefundLimits
127127
) {
128128
if (!isset($orderItemsById[$item->getOrderItemId()])) {
@@ -133,7 +133,7 @@ private function validateTotalQuantityRefundable(
133133
}
134134
$orderItem = $orderItemsById[$item->getOrderItemId()];
135135

136-
if ($this->isValidDecimalRefundQty($orderItem->getIsQtyDecimal(), $item->getQty())) {
136+
if (!$this->isValidDecimalRefundQty($orderItem->getIsQtyDecimal(), $item->getQty())) {
137137
return __(
138138
'We found an invalid quantity to refund item "%1".',
139139
$orderItem->getSku()

app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Validation/QuantityValidatorTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,19 @@ public function testValidateWithWrongItemId()
160160
* @param string $sku
161161
* @param int $total
162162
* @param array $expected
163+
* @param bool $isQtyDecimalAllowed
163164
* @dataProvider dataProviderForValidateQty
164165
*/
165-
public function testValidate($orderId, $orderItemId, $qtyToRequest, $qtyToRefund, $sku, $total, array $expected)
166-
{
166+
public function testValidate(
167+
$orderId,
168+
$orderItemId,
169+
$qtyToRequest,
170+
$qtyToRefund,
171+
$sku,
172+
$total,
173+
array $expected,
174+
bool $isQtyDecimalAllowed
175+
) {
167176
$creditmemoMock = $this->getMockBuilder(CreditmemoInterface::class)
168177
->disableOriginalConstructor()
169178
->getMockForAbstractClass();
@@ -190,6 +199,8 @@ public function testValidate($orderId, $orderItemId, $qtyToRequest, $qtyToRefund
190199
$orderItemMock = $this->getMockBuilder(Item::class)
191200
->disableOriginalConstructor()
192201
->getMock();
202+
$orderItemMock->expects($this->any())->method('getIsQtyDecimal')
203+
->willReturn($isQtyDecimalAllowed);
193204
$orderItemMock->expects($this->any())->method('getQtyToRefund')
194205
->willReturn($qtyToRefund);
195206
$creditmemoItemMock->expects($this->any())->method('getQty')
@@ -227,7 +238,8 @@ public function dataProviderForValidateQty()
227238
'qtyToRefund' => 1,
228239
'sku',
229240
'total' => 15,
230-
'expected' => []
241+
'expected' => [],
242+
'isQtyDecimalAllowed' => false
231243
],
232244
[
233245
'orderId' => 1,
@@ -236,22 +248,23 @@ public function dataProviderForValidateQty()
236248
'qtyToRefund' => 0,
237249
'sku',
238250
'total' => 15,
239-
'expected' => []
251+
'expected' => [],
252+
'isQtyDecimalAllowed' => false
240253
],
241254
[
242255
'orderId' => 1,
243256
'orderItemId' => 1,
244257
'qtyToRequest' => 1.5,
245-
'qtyToRefund' => 1,
258+
'qtyToRefund' => 3,
246259
'sku',
247-
'total' => 0,
260+
'total' => 5,
248261
'expected' => [
249262
__(
250263
'We found an invalid quantity to refund item "%1".',
251264
$sku
252-
),
253-
__('The credit memo\'s total must be positive.')
254-
]
265+
)
266+
],
267+
'isQtyDecimalAllowed' => false
255268
],
256269
[
257270
'orderId' => 1,
@@ -267,7 +280,8 @@ public function dataProviderForValidateQty()
267280
$sku
268281
),
269282
__('The credit memo\'s total must be positive.')
270-
]
283+
],
284+
'isQtyDecimalAllowed' => false
271285
],
272286
];
273287
}

0 commit comments

Comments
 (0)