Skip to content

Commit 166dd61

Browse files
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #15480: [Forwardport] Prevent not category links in breadcrumbs at product page #14994 (by @vovayatsyuk) - #14700: [2.3] Optimize ID to SKU lookup of tier prices (by @toddbc)
2 parents bed17e0 + b478457 commit 166dd61

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

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

+10-8
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
/**

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private function getCategoryAsArray($category, $currentCategory, $isParentActive
162162
'url' => $this->catalogCategory->getCategoryUrl($category),
163163
'has_active' => in_array((string)$category->getId(), explode('/', $currentCategory->getPath()), true),
164164
'is_active' => $category->getId() == $currentCategory->getId(),
165+
'is_category' => true,
165166
'is_parent_active' => $isParentActive
166167
];
167168
}

app/code/Magento/Catalog/view/frontend/web/js/product/breadcrumbs.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ define([
1616
categoryUrlSuffix: '',
1717
useCategoryPathInUrl: false,
1818
product: '',
19+
categoryItemSelector: '.category-item',
1920
menuContainer: '[data-action="navigation"] > ul'
2021
},
2122

@@ -163,7 +164,10 @@ define([
163164
categoryMenuItem = null;
164165

165166
if (categoryUrl && menu.length) {
166-
categoryMenuItem = menu.find('a[href="' + categoryUrl + '"]');
167+
categoryMenuItem = menu.find(
168+
this.options.categoryItemSelector +
169+
' > a[href="' + categoryUrl + '"]'
170+
);
167171
}
168172

169173
return categoryMenuItem;

app/code/Magento/Theme/Block/Html/Topmenu.php

+4
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ protected function _getMenuItemClasses(\Magento\Framework\Data\Tree\Node $item)
309309
$classes[] = 'level' . $item->getLevel();
310310
$classes[] = $item->getPositionClass();
311311

312+
if ($item->getIsCategory()) {
313+
$classes[] = 'category-item';
314+
}
315+
312316
if ($item->getIsFirst()) {
313317
$classes[] = 'first';
314318
}

dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/breadcrumbs.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ define([
1818
'Magento_Theme/js/model/breadcrumb-list': jasmine.createSpyObj(['push'])
1919
},
2020
defaultContext = require.s.contexts._,
21-
menuItem = $('<li class="level0"><a href="http://localhost.com/cat1.html" id="ui-id-3">Cat1</a></li>')[0],
21+
menuItem = $(
22+
'<li class="level0 category-item">' +
23+
'<a href="http://localhost.com/cat1.html" id="ui-id-3">Cat1</a>' +
24+
'</li>'
25+
)[0],
2226

2327
/**
2428
* Create context object.

0 commit comments

Comments
 (0)