13
13
use Magento \CatalogGraphQl \Model \Resolver \Product \Price \ProviderInterface ;
14
14
use Magento \ConfigurableProduct \Pricing \Price \ConfigurableOptionsProviderInterface ;
15
15
use Magento \Framework \Pricing \Amount \AmountInterface ;
16
+ use Magento \Framework \Pricing \Amount \BaseFactory ;
16
17
use Magento \Framework \Pricing \SaleableInterface ;
17
18
18
19
/**
@@ -25,6 +26,11 @@ class Provider implements ProviderInterface
25
26
*/
26
27
private $ optionsProvider ;
27
28
29
+ /**
30
+ * @var BaseFactory
31
+ */
32
+ private $ amountFactory ;
33
+
28
34
/**
29
35
* @var array
30
36
*/
@@ -43,11 +49,14 @@ class Provider implements ProviderInterface
43
49
44
50
/**
45
51
* @param ConfigurableOptionsProviderInterface $optionsProvider
52
+ * @param BaseFactory $amountFactory
46
53
*/
47
54
public function __construct (
48
- ConfigurableOptionsProviderInterface $ optionsProvider
55
+ ConfigurableOptionsProviderInterface $ optionsProvider ,
56
+ BaseFactory $ amountFactory
49
57
) {
50
58
$ this ->optionsProvider = $ optionsProvider ;
59
+ $ this ->amountFactory = $ amountFactory ;
51
60
}
52
61
53
62
/**
@@ -101,7 +110,7 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
101
110
{
102
111
if (!isset ($ this ->minimalPrice [$ code ][$ product ->getId ()])) {
103
112
$ minimumAmount = null ;
104
- foreach ($ this ->filterDisabledProducts ( $ this -> optionsProvider ->getProducts ($ product) ) as $ variant ) {
113
+ foreach ($ this ->optionsProvider ->getProducts ($ product ) as $ variant ) {
105
114
$ variantAmount = $ variant ->getPriceInfo ()->getPrice ($ code )->getAmount ();
106
115
if (!$ minimumAmount || ($ variantAmount ->getValue () < $ minimumAmount ->getValue ())) {
107
116
$ minimumAmount = $ variantAmount ;
@@ -110,7 +119,7 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
110
119
}
111
120
}
112
121
113
- return $ this ->minimalPrice [$ code ][$ product ->getId ()];
122
+ return $ this ->minimalPrice [$ code ][$ product ->getId ()] ?? $ this -> amountFactory -> create ([ ' amount ' => null ]) ;
114
123
}
115
124
116
125
/**
@@ -133,19 +142,6 @@ private function getMaximalPrice(SaleableInterface $product, string $code): Amou
133
142
}
134
143
}
135
144
136
- return $ this ->maximalPrice [$ code ][$ product ->getId ()];
137
- }
138
-
139
- /**
140
- * Filter out disabled products
141
- *
142
- * @param array $products
143
- * @return array
144
- */
145
- private function filterDisabledProducts (array $ products ): array
146
- {
147
- return array_filter ($ products , function ($ product ) {
148
- return (int )$ product ->getStatus () === ProductStatus::STATUS_ENABLED ;
149
- });
145
+ return $ this ->maximalPrice [$ code ][$ product ->getId ()] ?? $ this ->amountFactory ->create (['amount ' => null ]);
150
146
}
151
147
}
0 commit comments