Skip to content

Commit b478457

Browse files
author
Stanislav Idolov
authored
ENGCOM-1442: [2.3] Optimize ID to SKU lookup of tier prices #14700
2 parents 32ed351 + 51e6beb commit b478457

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

app/code/Magento/Catalog/Model/Product/Price/TierPriceStorage.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ private function getExistingPrices(array $skus, $groupBySku = false)
172172
$rawPrices = $this->tierPricePersistence->get($ids);
173173
$prices = [];
174174

175+
$linkField = $this->tierPricePersistence->getEntityLinkField();
176+
$skuByIdLookup = $this->buildSkuByIdLookup($skus);
175177
foreach ($rawPrices as $rawPrice) {
176-
$sku = $this->retrieveSkuById($rawPrice[$this->tierPricePersistence->getEntityLinkField()], $skus);
178+
$sku = $skuByIdLookup[$rawPrice[$linkField]];
177179
$price = $this->tierPriceFactory->create($rawPrice, $sku);
178180
if ($groupBySku) {
179181
$prices[$sku][] = $price;
@@ -300,21 +302,21 @@ private function isCorrectPriceValue(array $existingPrice, array $price)
300302
}
301303

302304
/**
303-
* Retrieve SKU by product ID.
305+
* Generate lookup to retrieve SKU by product ID.
304306
*
305-
* @param int $id
306307
* @param array $skus
307-
* @return string|null
308+
* @return array
308309
*/
309-
private function retrieveSkuById($id, $skus)
310+
private function buildSkuByIdLookup($skus)
310311
{
312+
$lookup = [];
311313
foreach ($this->productIdLocator->retrieveProductIdsBySkus($skus) as $sku => $ids) {
312-
if (isset($ids[$id])) {
313-
return $sku;
314+
foreach (array_keys($ids) as $id) {
315+
$lookup[$id] = $sku;
314316
}
315317
}
316318

317-
return null;
319+
return $lookup;
318320
}
319321

320322
/**

0 commit comments

Comments
 (0)