@@ -61,10 +61,12 @@ public function createByOrder(\Magento\Sales\Model\Order $order, array $data = [
61
61
62
62
$ item = $ this ->convertor ->itemToCreditmemoItem ($ orderItem );
63
63
if ($ orderItem ->isDummy ()) {
64
- $ qty = 1 ;
65
64
if (isset ($ data ['qtys ' ][$ orderItem ->getParentItemId ()])) {
66
- $ qty = $ this ->calculateProductOptions ($ orderItem , $ data ['qtys ' ]);
65
+ $ parentQty = $ data ['qtys ' ][$ orderItem ->getParentItemId ()];
66
+ } else {
67
+ $ parentQty = $ orderItem ->getParentItem () ? $ orderItem ->getParentItem ()->getQtyToRefund () : 1 ;
67
68
}
69
+ $ qty = $ this ->calculateProductOptions ($ orderItem , $ parentQty );
68
70
$ orderItem ->setLockedDoShip (true );
69
71
} else {
70
72
if (isset ($ qtys [$ orderItem ->getId ()])) {
@@ -139,10 +141,12 @@ public function createByInvoice(\Magento\Sales\Model\Order\Invoice $invoice, arr
139
141
140
142
$ item = $ this ->convertor ->itemToCreditmemoItem ($ orderItem );
141
143
if ($ orderItem ->isDummy ()) {
142
- $ qty = 1 ;
143
144
if (isset ($ data ['qtys ' ][$ orderItem ->getParentItemId ()])) {
144
- $ qty = $ this ->calculateProductOptions ($ orderItem , $ data ['qtys ' ]);
145
+ $ parentQty = $ data ['qtys ' ][$ orderItem ->getParentItemId ()];
146
+ } else {
147
+ $ parentQty = $ orderItem ->getParentItem () ? $ orderItem ->getParentItem ()->getQtyToRefund () : 1 ;
145
148
}
149
+ $ qty = $ this ->calculateProductOptions ($ orderItem , $ parentQty );
146
150
} else {
147
151
if (isset ($ qtys [$ orderItem ->getId ()])) {
148
152
$ qty = (double )$ qtys [$ orderItem ->getId ()];
@@ -261,15 +265,15 @@ protected function initData($creditmemo, $data)
261
265
* @param array $qtys
262
266
* @return int
263
267
*/
264
- private function calculateProductOptions (\Magento \Sales \Api \Data \OrderItemInterface $ orderItem , $ qtys )
268
+ private function calculateProductOptions (\Magento \Sales \Api \Data \OrderItemInterface $ orderItem , $ parentQty )
265
269
{
266
- $ qty = 1 ;
270
+ $ qty = $ parentQty ;
267
271
$ productOptions = $ orderItem ->getProductOptions ();
268
272
if (isset ($ productOptions ['bundle_selection_attributes ' ])) {
269
273
$ bundleSelectionAttributes = $ this ->getUnserialize ()
270
274
->unserialize ($ productOptions ['bundle_selection_attributes ' ]);
271
275
if ($ bundleSelectionAttributes ) {
272
- $ qty = $ bundleSelectionAttributes ['qty ' ] * $ qtys [ $ orderItem -> getParentItemId ()] ;
276
+ $ qty = $ bundleSelectionAttributes ['qty ' ] * $ parentQty ;
273
277
}
274
278
}
275
279
return $ qty ;
0 commit comments