9
9
10
10
use Magento \Catalog \Pricing \Price \FinalPrice ;
11
11
use Magento \Catalog \Pricing \Price \RegularPrice ;
12
+ use Magento \CatalogGraphQl \Model \Resolver \Product \Price \Provider as CatalogPriceProvider ;
12
13
use Magento \CatalogGraphQl \Model \Resolver \Product \Price \ProviderInterface ;
13
14
use Magento \ConfigurableProduct \Pricing \Price \ConfigurableOptionsProviderInterfaceFactory ;
14
15
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
@@ -52,17 +53,25 @@ class Provider implements ProviderInterface, ResetAfterRequestInterface
52
53
RegularPrice::PRICE_CODE => []
53
54
];
54
55
56
+ /**
57
+ * @var CatalogPriceProvider
58
+ */
59
+ private $ catalogPriceProvider ;
60
+
55
61
/**
56
62
* @param ConfigurableOptionsProviderInterfaceFactory $optionsProviderFactory
57
63
* @param BaseFactory $amountFactory
64
+ * @param CatalogPriceProvider $catalogPriceProvider
58
65
*/
59
66
public function __construct (
60
67
ConfigurableOptionsProviderInterfaceFactory $ optionsProviderFactory ,
61
- BaseFactory $ amountFactory
68
+ BaseFactory $ amountFactory ,
69
+ CatalogPriceProvider $ catalogPriceProvider
62
70
) {
63
71
$ this ->optionsProvider = $ optionsProviderFactory ->create ();
64
72
$ this ->optionsProviderFactory = $ optionsProviderFactory ;
65
73
$ this ->amountFactory = $ amountFactory ;
74
+ $ this ->catalogPriceProvider = $ catalogPriceProvider ;
66
75
}
67
76
68
77
/**
@@ -117,7 +126,13 @@ private function getMinimalPrice(SaleableInterface $product, string $code): Amou
117
126
if (!isset ($ this ->minimalPrice [$ code ][$ product ->getId ()])) {
118
127
$ minimumAmount = null ;
119
128
foreach ($ this ->optionsProvider ->getProducts ($ product ) as $ variant ) {
120
- $ variantAmount = $ variant ->getPriceInfo ()->getPrice ($ code )->getAmount ();
129
+ $ variantAmount = null ;
130
+ if ($ code === FinalPrice::PRICE_CODE ) {
131
+ $ variantAmount = $ this ->catalogPriceProvider ->getMinimalFinalPrice ($ variant );
132
+ } elseif ($ code === RegularPrice::PRICE_CODE ) {
133
+ $ variantAmount = $ this ->catalogPriceProvider ->getMinimalRegularPrice ($ variant );
134
+ }
135
+
121
136
if (!$ minimumAmount || ($ variantAmount ->getValue () < $ minimumAmount ->getValue ())) {
122
137
$ minimumAmount = $ variantAmount ;
123
138
$ this ->minimalPrice [$ code ][$ product ->getId ()] = $ variantAmount ;
@@ -140,7 +155,13 @@ private function getMaximalPrice(SaleableInterface $product, string $code): Amou
140
155
if (!isset ($ this ->maximalPrice [$ code ][$ product ->getId ()])) {
141
156
$ maximumAmount = null ;
142
157
foreach ($ this ->optionsProvider ->getProducts ($ product ) as $ variant ) {
143
- $ variantAmount = $ variant ->getPriceInfo ()->getPrice ($ code )->getAmount ();
158
+ $ variantAmount = null ;
159
+ if ($ code === FinalPrice::PRICE_CODE ) {
160
+ $ variantAmount = $ this ->catalogPriceProvider ->getMaximalFinalPrice ($ variant );
161
+ } elseif ($ code === RegularPrice::PRICE_CODE ) {
162
+ $ variantAmount = $ this ->catalogPriceProvider ->getMaximalRegularPrice ($ variant );
163
+ }
164
+
144
165
if (!$ maximumAmount || ($ variantAmount ->getValue () > $ maximumAmount ->getValue ())) {
145
166
$ maximumAmount = $ variantAmount ;
146
167
$ this ->maximalPrice [$ code ][$ product ->getId ()] = $ variantAmount ;
0 commit comments