@@ -120,47 +120,62 @@ function () use ($productId, $context) {
120
120
121
121
$ productPrice = $ this ->tiers ->getProductRegularPrice ($ productId ) ?? 0.0 ;
122
122
$ tierPrices = $ this ->tiers ->getProductTierPrices ($ productId ) ?? [];
123
- return $ this ->formatProductTierPrices ($ tierPrices , $ productPrice , $ store );
123
+ return $ this ->filterAndFormatProductTierPrices ($ tierPrices , $ productPrice , $ store );
124
124
}
125
125
);
126
126
}
127
127
128
128
/**
129
- * Format tier prices for output
129
+ * Filter and format tier prices for output
130
130
*
131
131
* @param ProductTierPriceInterface[] $tierPrices
132
132
* @param float $productPrice
133
133
* @param StoreInterface $store
134
134
* @return array
135
135
*/
136
- private function formatProductTierPrices (array $ tierPrices , float $ productPrice , StoreInterface $ store ): array
137
- {
136
+ private function filterAndFormatProductTierPrices (
137
+ array $ tierPrices ,
138
+ float $ productPrice ,
139
+ StoreInterface $ store
140
+ ): array {
138
141
$ tiers = [];
139
142
$ qtyCache = [];
140
143
141
144
foreach ($ tierPrices as $ key => $ tierPrice ) {
142
- $ tierPrice ->setValue ($ this ->priceCurrency ->convertAndRound ($ tierPrice ->getValue ()));
143
- $ percentValue = $ tierPrice ->getExtensionAttributes ()->getPercentageValue ();
144
- if ($ percentValue && is_numeric ($ percentValue )) {
145
- $ discount = $ this ->discount ->getDiscountByPercent ($ productPrice , (float )$ percentValue );
146
- } else {
147
- $ discount = $ this ->discount ->getDiscountByDifference ($ productPrice , (float )$ tierPrice ->getValue ());
148
- }
149
-
150
- $ tiers [] = [
151
- "discount " => $ discount ,
152
- "quantity " => $ tierPrice ->getQty (),
153
- "final_price " => [
154
- "value " => $ tierPrice ->getValue (),
155
- "currency " => $ store ->getCurrentCurrencyCode ()
156
- ]
157
- ];
158
-
145
+ $ this ->formatProductTierPrices ($ productPrice , $ store , $ tierPrice , $ tiers );
159
146
$ this ->filterTierPrices ($ tierPrices , $ key , $ tierPrice , $ qtyCache , $ tiers );
160
147
}
161
148
return $ tiers ;
162
149
}
163
150
151
+ /**
152
+ * Format tier prices for output
153
+ *
154
+ * @param float $productPrice
155
+ * @param StoreInterface $store
156
+ * @param $tierPrice
157
+ * @param $tiers
158
+ */
159
+ private function formatProductTierPrices (float $ productPrice , StoreInterface $ store , &$ tierPrice , &$ tiers )
160
+ {
161
+ $ tierPrice ->setValue ($ this ->priceCurrency ->convertAndRound ($ tierPrice ->getValue ()));
162
+ $ percentValue = $ tierPrice ->getExtensionAttributes ()->getPercentageValue ();
163
+ if ($ percentValue && is_numeric ($ percentValue )) {
164
+ $ discount = $ this ->discount ->getDiscountByPercent ($ productPrice , (float )$ percentValue );
165
+ } else {
166
+ $ discount = $ this ->discount ->getDiscountByDifference ($ productPrice , (float )$ tierPrice ->getValue ());
167
+ }
168
+
169
+ $ tiers [] = [
170
+ "discount " => $ discount ,
171
+ "quantity " => $ tierPrice ->getQty (),
172
+ "final_price " => [
173
+ "value " => $ tierPrice ->getValue (),
174
+ "currency " => $ store ->getCurrentCurrencyCode ()
175
+ ]
176
+ ];
177
+ }
178
+
164
179
/**
165
180
* Filter the lowest price for each quantity
166
181
*
0 commit comments