@@ -42,11 +42,6 @@ class Item extends AbstractModel implements CreditmemoItemInterface
42
42
*/
43
43
protected $ _orderItemFactory ;
44
44
45
- /**
46
- * @var bool
47
- */
48
- private $ qtyProcessed = false ;
49
-
50
45
/**
51
46
* @param \Magento\Framework\Model\Context $context
52
47
* @param \Magento\Framework\Registry $registry
@@ -163,7 +158,6 @@ private function isQtyAvailable($qty, \Magento\Sales\Model\Order\Item $orderItem
163
158
public function setQty ($ qty )
164
159
{
165
160
$ this ->setData ('qty ' , $ qty );
166
- $ this ->qtyProcessed = false ;
167
161
return $ this ;
168
162
}
169
163
@@ -176,7 +170,8 @@ public function register()
176
170
{
177
171
$ orderItem = $ this ->getOrderItem ();
178
172
179
- $ orderItem ->setQtyRefunded ($ orderItem ->getQtyRefunded () + $ this ->getQty ());
173
+ $ qty = $ this ->processQty ();
174
+ $ orderItem ->setQtyRefunded ($ orderItem ->getQtyRefunded () + $ qty );
180
175
$ orderItem ->setTaxRefunded ($ orderItem ->getTaxRefunded () + $ this ->getTaxAmount ());
181
176
$ orderItem ->setBaseTaxRefunded ($ orderItem ->getBaseTaxRefunded () + $ this ->getBaseTaxAmount ());
182
177
$ orderItem ->setDiscountTaxCompensationRefunded (
@@ -194,7 +189,7 @@ public function register()
194
189
}
195
190
196
191
/**
197
- * @return void
192
+ * @return int|float
198
193
* @throws \Magento\Framework\Exception\LocalizedException
199
194
*/
200
195
private function processQty ()
@@ -208,7 +203,7 @@ private function processQty()
208
203
}
209
204
$ qty = $ qty > 0 ? $ qty : 0 ;
210
205
if ($ this ->isQtyAvailable ($ qty , $ orderItem )) {
211
- $ this -> setData ( ' qty ' , $ qty) ;
206
+ return $ qty ;
212
207
} else {
213
208
throw new \Magento \Framework \Exception \LocalizedException (
214
209
__ ('We found an invalid quantity to refund item "%1". ' , $ this ->getName ())
@@ -221,17 +216,18 @@ private function processQty()
221
216
*/
222
217
public function cancel ()
223
218
{
224
- $ this ->getOrderItem ()->setQtyRefunded ($ this ->getOrderItem ()->getQtyRefunded () - $ this ->getQty ());
219
+ $ qty = $ this ->processQty ();
220
+ $ this ->getOrderItem ()->setQtyRefunded ($ this ->getOrderItem ()->getQtyRefunded () - $ qty );
225
221
$ this ->getOrderItem ()->setTaxRefunded (
226
222
$ this ->getOrderItem ()->getTaxRefunded () -
227
223
$ this ->getOrderItem ()->getBaseTaxAmount () *
228
- $ this -> getQty () /
224
+ $ qty /
229
225
$ this ->getOrderItem ()->getQtyOrdered ()
230
226
);
231
227
$ this ->getOrderItem ()->setDiscountTaxCompensationRefunded (
232
228
$ this ->getOrderItem ()->getDiscountTaxCompensationRefunded () -
233
229
$ this ->getOrderItem ()->getDiscountTaxCompensationAmount () *
234
- $ this -> getQty () /
230
+ $ qty /
235
231
$ this ->getOrderItem ()->getQtyOrdered ()
236
232
);
237
233
return $ this ;
@@ -253,21 +249,22 @@ public function calcRowTotal()
253
249
$ rowTotalInclTax = $ orderItem ->getRowTotalInclTax ();
254
250
$ baseRowTotalInclTax = $ orderItem ->getBaseRowTotalInclTax ();
255
251
256
- if (!$ this ->isLast () && $ orderItemQtyInvoiced > 0 && $ this ->getQty () >= 0 ) {
252
+ $ qty = $ this ->processQty ();
253
+ if (!$ this ->isLast () && $ orderItemQtyInvoiced > 0 && $ qty >= 0 ) {
257
254
$ availableQty = $ orderItemQtyInvoiced - $ orderItem ->getQtyRefunded ();
258
- $ rowTotal = $ creditmemo ->roundPrice ($ rowTotal / $ availableQty * $ this -> getQty () );
259
- $ baseRowTotal = $ creditmemo ->roundPrice ($ baseRowTotal / $ availableQty * $ this -> getQty () , 'base ' );
255
+ $ rowTotal = $ creditmemo ->roundPrice ($ rowTotal / $ availableQty * $ qty );
256
+ $ baseRowTotal = $ creditmemo ->roundPrice ($ baseRowTotal / $ availableQty * $ qty , 'base ' );
260
257
}
261
258
$ this ->setRowTotal ($ rowTotal );
262
259
$ this ->setBaseRowTotal ($ baseRowTotal );
263
260
264
261
if ($ rowTotalInclTax && $ baseRowTotalInclTax ) {
265
262
$ orderItemQty = $ orderItem ->getQtyOrdered ();
266
263
$ this ->setRowTotalInclTax (
267
- $ creditmemo ->roundPrice ($ rowTotalInclTax / $ orderItemQty * $ this -> getQty () , 'including ' )
264
+ $ creditmemo ->roundPrice ($ rowTotalInclTax / $ orderItemQty * $ qty , 'including ' )
268
265
);
269
266
$ this ->setBaseRowTotalInclTax (
270
- $ creditmemo ->roundPrice ($ baseRowTotalInclTax / $ orderItemQty * $ this -> getQty () , 'including_base ' )
267
+ $ creditmemo ->roundPrice ($ baseRowTotalInclTax / $ orderItemQty * $ qty , 'including_base ' )
271
268
);
272
269
}
273
270
return $ this ;
@@ -281,7 +278,8 @@ public function calcRowTotal()
281
278
public function isLast ()
282
279
{
283
280
$ orderItem = $ this ->getOrderItem ();
284
- if ((string )(double )$ this ->getQty () == (string )(double )$ orderItem ->getQtyToRefund ()) {
281
+ $ qty = $ this ->processQty ();
282
+ if ((string )(double )$ qty == (string )(double )$ orderItem ->getQtyToRefund ()) {
285
283
return true ;
286
284
}
287
285
return false ;
@@ -514,10 +512,6 @@ public function getProductId()
514
512
*/
515
513
public function getQty ()
516
514
{
517
- if (!$ this ->qtyProcessed ) {
518
- $ this ->processQty ();
519
- $ this ->qtyProcessed = true ;
520
- }
521
515
return $ this ->getData (CreditmemoItemInterface::QTY );
522
516
}
523
517
0 commit comments