File tree Expand file tree Collapse file tree 3 files changed +16
-31
lines changed Expand file tree Collapse file tree 3 files changed +16
-31
lines changed Original file line number Diff line number Diff line change 6
6
namespace Magento \CatalogInventory \Block \Plugin ;
7
7
8
8
use Magento \CatalogInventory \Model \Product \QuantityValidator ;
9
+ use Magento \Framework \App \ObjectManager ;
9
10
10
11
class ProductView
11
12
{
@@ -15,12 +16,14 @@ class ProductView
15
16
private $ productQuantityValidator ;
16
17
17
18
/**
18
- * @param QuantityValidator $productQuantityValidator
19
+ * @param QuantityValidator|null $productQuantityValidator
19
20
*/
20
21
public function __construct (
21
- QuantityValidator $ productQuantityValidator
22
+ QuantityValidator $ productQuantityValidator = null
22
23
) {
23
- $ this ->productQuantityValidator = $ productQuantityValidator ;
24
+ $ this ->productQuantityValidator = $ productQuantityValidator ?: ObjectManager::getInstance ()->get (
25
+ QuantityValidator::class
26
+ );
24
27
}
25
28
26
29
/**
Original file line number Diff line number Diff line change 11
11
12
12
class QuantityValidator
13
13
{
14
- /**
15
- * @var StockRegistryInterface
16
- */
17
- private $ stockRegistry ;
18
-
19
14
/**
20
15
* @param StockRegistryInterface $stockRegistry
21
16
*/
22
17
public function __construct (
23
- StockRegistryInterface $ stockRegistry
18
+ private readonly StockRegistryInterface $ stockRegistry
24
19
) {
25
- $ this ->stockRegistry = $ stockRegistry ;
26
20
}
27
21
28
22
/**
29
23
* To get quantity validators
30
24
*
31
25
* @param int $productId
32
- * @param int $websiteId
26
+ * @param int|null $websiteId
33
27
*
34
28
* @return array
35
29
*/
36
- public function getData ($ productId , $ websiteId ): array
30
+ public function getData (int $ productId , int | null $ websiteId ): array
37
31
{
38
32
$ stockItem = $ this ->stockRegistry ->getStockItem ($ productId , $ websiteId );
39
33
40
34
$ params = [];
41
35
$ validators = [];
42
- $ params ['minAllowed ' ] = ( float ) $ stockItem ->getMinSaleQty ();
36
+ $ params ['minAllowed ' ] = $ stockItem ->getMinSaleQty ();
43
37
if ($ stockItem ->getMaxSaleQty ()) {
44
- $ params ['maxAllowed ' ] = ( float ) $ stockItem ->getMaxSaleQty ();
38
+ $ params ['maxAllowed ' ] = $ stockItem ->getMaxSaleQty ();
45
39
}
46
40
if ($ stockItem ->getQtyIncrements () > 0 ) {
47
- $ params ['qtyIncrements ' ] = (float )$ stockItem ->getQtyIncrements ();
41
+ $ params ['qtyIncrements ' ] = (float ) $ stockItem ->getQtyIncrements ();
48
42
}
49
43
$ validators ['validate-item-quantity ' ] = $ params ;
50
44
Original file line number Diff line number Diff line change 16
16
*/
17
17
class ValidateQuantity implements ArgumentInterface
18
18
{
19
- /**
20
- * @var Json
21
- */
22
- private $ serializer ;
23
-
24
- /**
25
- * @var QuantityValidator
26
- */
27
- private $ productQuantityValidator ;
28
-
29
19
/**
30
20
* @param Json $serializer
31
21
* @param QuantityValidator $productQuantityValidator
32
22
*/
33
23
public function __construct (
34
- Json $ serializer ,
35
- QuantityValidator $ productQuantityValidator ,
24
+ private readonly Json $ serializer ,
25
+ private readonly QuantityValidator $ productQuantityValidator ,
36
26
) {
37
- $ this ->serializer = $ serializer ;
38
- $ this ->productQuantityValidator = $ productQuantityValidator ;
39
27
}
40
28
41
29
/**
42
30
* To get the quantity validators
43
31
*
44
32
* @param int $productId
45
- * @param int $websiteId
33
+ * @param int|null $websiteId
46
34
*
47
35
* @return string
48
36
*/
49
- public function getQuantityValidators ($ productId , $ websiteId ): string
37
+ public function getQuantityValidators (int $ productId , int | null $ websiteId ): string
50
38
{
51
39
return $ this ->serializer ->serialize (
52
40
array_merge (
You can’t perform that action at this time.
0 commit comments