@@ -188,35 +188,14 @@ private function isQtyAvailable(Item $orderItem, $qty)
188
188
* @param double $qty
189
189
* @param array $invoiceQtysRefundLimits
190
190
* @return bool
191
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
192
191
*/
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 )
194
193
{
195
194
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 );
219
196
}
197
+
198
+ return $ this ->canRefundNoDummyItem ($ item , $ invoiceQtysRefundLimits );
220
199
}
221
200
222
201
/**
@@ -226,7 +205,7 @@ private function canRefundItem(\Magento\Sales\Model\Order\Item $item, $qty, $inv
226
205
* @param array $invoiceQtysRefundLimits
227
206
* @return bool
228
207
*/
229
- private function canRefundNoDummyItem ($ item , $ invoiceQtysRefundLimits = [])
208
+ private function canRefundNoDummyItem (\ Magento \ Sales \ Model \ Order \ Item $ item , array $ invoiceQtysRefundLimits = [])
230
209
{
231
210
if ($ item ->getQtyToRefund () < 0 ) {
232
211
return false ;
@@ -236,4 +215,39 @@ private function canRefundNoDummyItem($item, $invoiceQtysRefundLimits = [])
236
215
}
237
216
return true ;
238
217
}
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
+ }
239
253
}
0 commit comments