Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions app/code/Magento/Catalog/Model/Product/Price/TierPriceStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ private function getExistingPrices(array $skus, $groupBySku = false)
$rawPrices = $this->tierPricePersistence->get($ids);
$prices = [];

$linkField = $this->tierPricePersistence->getEntityLinkField();
$skuByIdLookup = $this->buildSkuByIdLookup($skus);
foreach ($rawPrices as $rawPrice) {
$sku = $this->retrieveSkuById($rawPrice[$this->tierPricePersistence->getEntityLinkField()], $skus);
$sku = $skuByIdLookup[$rawPrice[$linkField]];
$price = $this->tierPriceFactory->create($rawPrice, $sku);
if ($groupBySku) {
$prices[$sku][] = $price;
Expand Down Expand Up @@ -300,21 +302,21 @@ private function isCorrectPriceValue(array $existingPrice, array $price)
}

/**
* Retrieve SKU by product ID.
* Generate lookup to retrieve SKU by product ID.
*
* @param int $id
* @param array $skus
* @return string|null
* @return array
*/
private function retrieveSkuById($id, $skus)
private function buildSkuByIdLookup($skus)
{
$lookup = [];
foreach ($this->productIdLocator->retrieveProductIdsBySkus($skus) as $sku => $ids) {
if (isset($ids[$id])) {
return $sku;
foreach (array_keys($ids) as $id) {
$lookup[$id] = $sku;
}
}

return null;
return $lookup;
}

/**
Expand Down