Skip to content

Commit 03eb42a

Browse files
committed
MAGETWO-54680: Order status change after Creditmemo creation through API. L3 fixes
1 parent f2eaac3 commit 03eb42a

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

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

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -188,35 +188,14 @@ private function isQtyAvailable(Item $orderItem, $qty)
188188
* @param double $qty
189189
* @param array $invoiceQtysRefundLimits
190190
* @return bool
191-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
192191
*/
193-
private function canRefundItem(\Magento\Sales\Model\Order\Item $item, $qty, $invoiceQtysRefundLimits)
192+
private function canRefundItem(\Magento\Sales\Model\Order\Item $item, $qty, array $invoiceQtysRefundLimits)
194193
{
195194
if ($item->isDummy()) {
196-
if ($item->getHasChildren()) {
197-
foreach ($item->getChildrenItems() as $child) {
198-
if ($qty === null) {
199-
if ($this->canRefundNoDummyItem($child, $invoiceQtysRefundLimits)) {
200-
return true;
201-
}
202-
} else {
203-
if ($qty > 0) {
204-
return true;
205-
}
206-
}
207-
}
208-
return false;
209-
} elseif ($item->getParentItem()) {
210-
$parent = $item->getParentItem();
211-
if ($qty === null) {
212-
return $this->canRefundNoDummyItem($parent, $invoiceQtysRefundLimits);
213-
} else {
214-
return $qty > 0;
215-
}
216-
}
217-
} else {
218-
return $this->canRefundNoDummyItem($item, $invoiceQtysRefundLimits);
195+
return $this->canRefundDummyItem($item, $qty, $invoiceQtysRefundLimits);
219196
}
197+
198+
return $this->canRefundNoDummyItem($item, $invoiceQtysRefundLimits);
220199
}
221200

222201
/**
@@ -226,7 +205,7 @@ private function canRefundItem(\Magento\Sales\Model\Order\Item $item, $qty, $inv
226205
* @param array $invoiceQtysRefundLimits
227206
* @return bool
228207
*/
229-
private function canRefundNoDummyItem($item, $invoiceQtysRefundLimits = [])
208+
private function canRefundNoDummyItem(\Magento\Sales\Model\Order\Item $item, array $invoiceQtysRefundLimits = [])
230209
{
231210
if ($item->getQtyToRefund() < 0) {
232211
return false;
@@ -236,4 +215,39 @@ private function canRefundNoDummyItem($item, $invoiceQtysRefundLimits = [])
236215
}
237216
return true;
238217
}
218+
219+
/**
220+
* @param Item $item
221+
* @param int $qty
222+
* @param array $invoiceQtysRefundLimits
223+
* @return bool
224+
*/
225+
private function canRefundDummyItem(\Magento\Sales\Model\Order\Item $item, $qty, array $invoiceQtysRefundLimits)
226+
{
227+
if ($item->getHasChildren()) {
228+
foreach ($item->getChildrenItems() as $child) {
229+
if ($this->canRefundRequestedQty($child, $qty, $invoiceQtysRefundLimits)) {
230+
return true;
231+
}
232+
}
233+
} elseif ($item->getParentItem()) {
234+
return $this->canRefundRequestedQty($item->getParentItem(), $qty, $invoiceQtysRefundLimits);
235+
}
236+
237+
return false;
238+
}
239+
240+
/**
241+
* @param Item $item
242+
* @param int $qty
243+
* @param array $invoiceQtysRefundLimits
244+
* @return bool
245+
*/
246+
private function canRefundRequestedQty(
247+
\Magento\Sales\Model\Order\Item $item,
248+
$qty,
249+
array $invoiceQtysRefundLimits
250+
) {
251+
return $qty === null ? $this->canRefundNoDummyItem($item, $invoiceQtysRefundLimits) : $qty > 0;
252+
}
239253
}

0 commit comments

Comments
 (0)