@@ -134,29 +134,31 @@ function () use ($productId, $context) {
134
134
135
135
$ productPrice = $ this ->tiers ->getProductRegularPrice ($ productId ) ?? 0.0 ;
136
136
$ tierPrices = $ this ->tiers ->getProductTierPrices ($ productId ) ?? [];
137
- return $ this ->formatAndFilterTierPrices ($ tierPrices , $ productPrice , $ currencyCode );
137
+ return $ this ->formatAndFilterTierPrices ($ productId , $ productPrice, $ tierPrices , $ currencyCode );
138
138
}
139
139
);
140
140
}
141
141
142
142
/**
143
143
* Format and filter tier prices for output
144
144
*
145
- * @param ProductTierPriceInterface[] $tierPrices
145
+ * @param int $productId
146
146
* @param float $productPrice
147
+ * @param ProductTierPriceInterface[] $tierPrices
147
148
* @param string $currencyCode
148
149
* @return array
149
150
*/
150
151
private function formatAndFilterTierPrices (
151
- array $ tierPrices ,
152
+ int $ productId ,
152
153
float $ productPrice ,
154
+ array $ tierPrices ,
153
155
string $ currencyCode
154
156
): array {
155
157
156
158
foreach ($ tierPrices as $ key => $ tierPrice ) {
157
159
$ tierPrice ->setValue ($ this ->priceCurrency ->convertAndRound ($ tierPrice ->getValue ()));
158
160
$ this ->formatTierPrices ($ productPrice , $ currencyCode , $ tierPrice );
159
- $ this ->filterTierPrices ($ tierPrices , $ key , $ tierPrice );
161
+ $ this ->filterTierPrices ($ productId , $ tierPrices , $ key , $ tierPrice );
160
162
}
161
163
return $ this ->formatAndFilterTierPrices ;
162
164
}
@@ -190,26 +192,28 @@ private function formatTierPrices(float $productPrice, string $currencyCode, $ti
190
192
/**
191
193
* Filter the lowest price for each quantity
192
194
*
195
+ * @param int $productId
193
196
* @param array $tierPrices
194
197
* @param int $key
195
198
* @param ProductTierPriceInterface $tierPriceItem
196
199
*/
197
200
private function filterTierPrices (
201
+ int $ productId ,
198
202
array $ tierPrices ,
199
203
int $ key ,
200
204
ProductTierPriceInterface $ tierPriceItem
201
205
) {
202
206
$ qty = $ tierPriceItem ->getQty ();
203
- if (isset ($ this ->tierPricesQty [$ qty ])) {
204
- $ priceQty = $ this ->tierPricesQty [$ qty ];
207
+ if (isset ($ this ->tierPricesQty [$ productId ][ $ qty ])) {
208
+ $ priceQty = $ this ->tierPricesQty [$ productId ][ $ qty ];
205
209
if ((float )$ tierPriceItem ->getValue () < (float )$ tierPrices [$ priceQty ]->getValue ()) {
206
210
unset($ this ->formatAndFilterTierPrices [$ priceQty ]);
207
- $ this ->tierPricesQty [$ priceQty ] = $ key ;
211
+ $ this ->tierPricesQty [$ productId ][ $ priceQty ] = $ key ;
208
212
} else {
209
213
unset($ this ->formatAndFilterTierPrices [$ key ]);
210
214
}
211
215
} else {
212
- $ this ->tierPricesQty [$ qty ] = $ key ;
216
+ $ this ->tierPricesQty [$ productId ][ $ qty ] = $ key ;
213
217
}
214
218
}
215
219
}
0 commit comments