12
12
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
13
13
use Magento \Customer \Model \GroupManagement ;
14
14
use Magento \Catalog \Api \Data \ProductTierPriceInterface ;
15
+ use Magento \CatalogGraphQl \Model \Resolver \Product \Price \ProviderPool as PriceProviderPool ;
15
16
16
17
/**
17
18
* Get product tier price information
@@ -28,6 +29,11 @@ class Tiers
28
29
*/
29
30
private $ productResource ;
30
31
32
+ /**
33
+ * @var PriceProviderPool
34
+ */
35
+ private $ priceProviderPool ;
36
+
31
37
/**
32
38
* @var bool
33
39
*/
@@ -36,7 +42,7 @@ class Tiers
36
42
/**
37
43
* @var int
38
44
*/
39
- private $ customerGroupId = GroupManagement::CUST_GROUP_ALL ;
45
+ private $ customerGroupId = GroupManagement::CUST_GROUP_ALL ;
40
46
41
47
/**
42
48
* @var array
@@ -51,15 +57,18 @@ class Tiers
51
57
/**
52
58
* @param CollectionFactory $collectionFactory
53
59
* @param ProductResource $productResource
60
+ * @param PriceProviderPool $priceProviderPool
54
61
* @param int $customerGroupId
55
62
*/
56
63
public function __construct (
57
64
CollectionFactory $ collectionFactory ,
58
65
ProductResource $ productResource ,
66
+ PriceProviderPool $ priceProviderPool ,
59
67
$ customerGroupId
60
68
) {
61
69
$ this ->collectionFactory = $ collectionFactory ;
62
70
$ this ->productResource = $ productResource ;
71
+ $ this ->priceProviderPool = $ priceProviderPool ;
63
72
$ this ->customerGroupId = $ customerGroupId ;
64
73
}
65
74
@@ -91,6 +100,26 @@ public function getProductTierPrices($productId): ?array
91
100
return $ this ->products [$ productId ]->getTierPrices ();
92
101
}
93
102
103
+ /**
104
+ * Get product regular price by ID
105
+ *
106
+ * @param int $productId
107
+ * @return float|null
108
+ */
109
+ public function getProductRegularPrice ($ productId ): ?float
110
+ {
111
+ if (!$ this ->isLoaded ()) {
112
+ $ this ->load ();
113
+ }
114
+
115
+ if (empty ($ this ->products [$ productId ])) {
116
+ return null ;
117
+ }
118
+ $ product = $ this ->products [$ productId ];
119
+ $ priceProvider = $ this ->priceProviderPool ->getProviderByProductType ($ product ->getTypeId ());
120
+ return $ priceProvider ->getMinimalRegularPrice ($ product )->getValue ();
121
+ }
122
+
94
123
/**
95
124
* Check if collection has been loaded
96
125
*
@@ -112,6 +141,8 @@ private function load(): void
112
141
/** @var Collection $productCollection */
113
142
$ productCollection = $ this ->collectionFactory ->create ();
114
143
$ productCollection ->addFieldToFilter ($ productIdField , ['in ' => $ this ->filterProductIds ]);
144
+ $ productCollection ->addAttributeToSelect ('price ' );
145
+ $ productCollection ->load ();
115
146
$ productCollection ->addTierPriceDataByGroupId ($ this ->customerGroupId );
116
147
117
148
foreach ($ productCollection as $ product ) {
0 commit comments