1313use Magento \CatalogGraphQl \Model \Resolver \Product \Price \ProviderInterface ;
1414use Magento \ConfigurableProduct \Pricing \Price \ConfigurableOptionsProviderInterface ;
1515use Magento \Framework \Pricing \Amount \AmountInterface ;
16+ use Magento \Framework \Pricing \Amount \BaseFactory ;
1617use Magento \Framework \Pricing \SaleableInterface ;
1718
1819/**
@@ -25,6 +26,11 @@ class Provider implements ProviderInterface
2526 */
2627 private $ optionsProvider ;
2728
29+ /**
30+ * @var BaseFactory
31+ */
32+ private $ amountFactory ;
33+
2834 /**
2935 * @var array
3036 */
@@ -43,11 +49,14 @@ class Provider implements ProviderInterface
4349
4450 /**
4551 * @param ConfigurableOptionsProviderInterface $optionsProvider
52+ * @param BaseFactory $amountFactory
4653 */
4754 public function __construct (
48- ConfigurableOptionsProviderInterface $ optionsProvider
55+ ConfigurableOptionsProviderInterface $ optionsProvider ,
56+ BaseFactory $ amountFactory
4957 ) {
5058 $ this ->optionsProvider = $ optionsProvider ;
59+ $ this ->amountFactory = $ amountFactory ;
5160 }
5261
5362 /**
@@ -101,7 +110,7 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
101110 {
102111 if (!isset ($ this ->minimalPrice [$ code ][$ product ->getId ()])) {
103112 $ minimumAmount = null ;
104- foreach ($ this ->filterDisabledProducts ( $ this -> optionsProvider ->getProducts ($ product) ) as $ variant ) {
113+ foreach ($ this ->optionsProvider ->getProducts ($ product ) as $ variant ) {
105114 $ variantAmount = $ variant ->getPriceInfo ()->getPrice ($ code )->getAmount ();
106115 if (!$ minimumAmount || ($ variantAmount ->getValue () < $ minimumAmount ->getValue ())) {
107116 $ minimumAmount = $ variantAmount ;
@@ -110,7 +119,7 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
110119 }
111120 }
112121
113- return $ this ->minimalPrice [$ code ][$ product ->getId ()];
122+ return $ this ->minimalPrice [$ code ][$ product ->getId ()] ?? $ this -> amountFactory -> create ([ ' amount ' => null ]) ;
114123 }
115124
116125 /**
@@ -133,19 +142,6 @@ private function getMaximalPrice(SaleableInterface $product, string $code): Amou
133142 }
134143 }
135144
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 ]);
150146 }
151147}
0 commit comments