3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Sales \Model \Order \Creditmemo \Validation ;
7
9
10
+ use Magento \Framework \Pricing \PriceCurrencyInterface ;
8
11
use Magento \Sales \Api \Data \CreditmemoInterface ;
9
12
use Magento \Sales \Api \Data \OrderInterface ;
10
13
use Magento \Sales \Api \Data \OrderItemInterface ;
11
14
use Magento \Sales \Api \InvoiceRepositoryInterface ;
12
15
use Magento \Sales \Api \OrderRepositoryInterface ;
13
- use Magento \Sales \Model \Order ;
14
16
use Magento \Sales \Model \Order \Creditmemo ;
15
17
use Magento \Sales \Model \Order \Item ;
16
18
use Magento \Sales \Model \ValidatorInterface ;
17
19
18
20
/**
19
- * Class QuantityValidator
21
+ * Creditmemo QuantityValidator
20
22
*/
21
23
class QuantityValidator implements ValidatorInterface
22
24
{
@@ -31,7 +33,7 @@ class QuantityValidator implements ValidatorInterface
31
33
private $ invoiceRepository ;
32
34
33
35
/**
34
- * @var \Magento\Framework\Pricing\ PriceCurrencyInterface
36
+ * @var PriceCurrencyInterface
35
37
*/
36
38
private $ priceCurrency ;
37
39
@@ -40,12 +42,12 @@ class QuantityValidator implements ValidatorInterface
40
42
*
41
43
* @param OrderRepositoryInterface $orderRepository
42
44
* @param InvoiceRepositoryInterface $invoiceRepository
43
- * @param \Magento\Framework\Pricing\ PriceCurrencyInterface $priceCurrency
45
+ * @param PriceCurrencyInterface $priceCurrency
44
46
*/
45
47
public function __construct (
46
48
OrderRepositoryInterface $ orderRepository ,
47
49
InvoiceRepositoryInterface $ invoiceRepository ,
48
- \ Magento \ Framework \ Pricing \ PriceCurrencyInterface $ priceCurrency
50
+ PriceCurrencyInterface $ priceCurrency
49
51
) {
50
52
$ this ->orderRepository = $ orderRepository ;
51
53
$ this ->invoiceRepository = $ invoiceRepository ;
@@ -96,7 +98,7 @@ public function validate($entity)
96
98
97
99
if ($ entity ->getGrandTotal () <= 0 ) {
98
100
$ messages [] = __ ('The credit memo \'s total must be positive. ' );
99
- } elseif ($ totalQuantity <= 0 && !$ this ->canRefundShipping ($ order )) {
101
+ } elseif ($ totalQuantity < 0 && !$ this ->canRefundShipping ($ order )) {
100
102
$ messages [] = __ ('You can \'t create a creditmemo without products. ' );
101
103
}
102
104
@@ -117,6 +119,8 @@ private function canRefundShipping(OrderInterface $order)
117
119
}
118
120
119
121
/**
122
+ * Invoice qty refund limits
123
+ *
120
124
* @param CreditmemoInterface $creditmemo
121
125
* @param OrderInterface $order
122
126
* @return array
@@ -156,6 +160,8 @@ private function getInvoiceQtysRefundLimits(CreditmemoInterface $creditmemo, Ord
156
160
}
157
161
158
162
/**
163
+ * Get order items
164
+ *
159
165
* @param OrderInterface $order
160
166
* @return OrderItemInterface[]
161
167
*/
@@ -170,6 +176,8 @@ private function getOrderItems(OrderInterface $order)
170
176
}
171
177
172
178
/**
179
+ * Check is qty available
180
+ *
173
181
* @param Item $orderItem
174
182
* @param int $qty
175
183
* @return bool
@@ -182,12 +190,12 @@ private function isQtyAvailable(Item $orderItem, $qty)
182
190
/**
183
191
* Check if order item can be refunded
184
192
*
185
- * @param \Magento\Sales\Model\Order\ Item $item
193
+ * @param Item $item
186
194
* @param double $qty
187
195
* @param array $invoiceQtysRefundLimits
188
196
* @return bool
189
197
*/
190
- private function canRefundItem (\ Magento \ Sales \ Model \ Order \ Item $ item , $ qty , array $ invoiceQtysRefundLimits )
198
+ private function canRefundItem (Item $ item , $ qty , array $ invoiceQtysRefundLimits )
191
199
{
192
200
if ($ item ->isDummy ()) {
193
201
return $ this ->canRefundDummyItem ($ item , $ qty , $ invoiceQtysRefundLimits );
@@ -199,11 +207,11 @@ private function canRefundItem(\Magento\Sales\Model\Order\Item $item, $qty, arra
199
207
/**
200
208
* Check if no dummy order item can be refunded
201
209
*
202
- * @param \Magento\Sales\Model\Order\ Item $item
210
+ * @param Item $item
203
211
* @param array $invoiceQtysRefundLimits
204
212
* @return bool
205
213
*/
206
- private function canRefundNoDummyItem (\ Magento \ Sales \ Model \ Order \ Item $ item , array $ invoiceQtysRefundLimits = [])
214
+ private function canRefundNoDummyItem (Item $ item , array $ invoiceQtysRefundLimits = [])
207
215
{
208
216
if ($ item ->getQtyToRefund () < 0 ) {
209
217
return false ;
@@ -215,12 +223,14 @@ private function canRefundNoDummyItem(\Magento\Sales\Model\Order\Item $item, arr
215
223
}
216
224
217
225
/**
226
+ * Check can refund dummy item
227
+ *
218
228
* @param Item $item
219
229
* @param int $qty
220
230
* @param array $invoiceQtysRefundLimits
221
231
* @return bool
222
232
*/
223
- private function canRefundDummyItem (\ Magento \ Sales \ Model \ Order \ Item $ item , $ qty , array $ invoiceQtysRefundLimits )
233
+ private function canRefundDummyItem (Item $ item , $ qty , array $ invoiceQtysRefundLimits )
224
234
{
225
235
if ($ item ->getHasChildren ()) {
226
236
foreach ($ item ->getChildrenItems () as $ child ) {
@@ -236,16 +246,15 @@ private function canRefundDummyItem(\Magento\Sales\Model\Order\Item $item, $qty,
236
246
}
237
247
238
248
/**
249
+ * Check can refund request qty
250
+ *
239
251
* @param Item $item
240
252
* @param int $qty
241
253
* @param array $invoiceQtysRefundLimits
242
254
* @return bool
243
255
*/
244
- private function canRefundRequestedQty (
245
- \Magento \Sales \Model \Order \Item $ item ,
246
- $ qty ,
247
- array $ invoiceQtysRefundLimits
248
- ) {
256
+ private function canRefundRequestedQty (Item $ item , $ qty , array $ invoiceQtysRefundLimits )
257
+ {
249
258
return $ qty === null ? $ this ->canRefundNoDummyItem ($ item , $ invoiceQtysRefundLimits ) : $ qty > 0 ;
250
259
}
251
260
}
0 commit comments