Skip to content

Commit d5e8a26

Browse files
Patch for wrong category names.
1 parent 10324c9 commit d5e8a26

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Model/Resolver/Menu.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function __construct(
9090
* @return array
9191
*
9292
* @throws NoSuchEntityException
93+
* @throws \Magento\Framework\Exception\LocalizedException
9394
*/
9495
public function resolve(
9596
Field $field,
@@ -121,6 +122,7 @@ public function resolve(
121122
/**
122123
* @param string $menuId
123124
* @return array
125+
* @throws \Magento\Framework\Exception\LocalizedException
124126
*/
125127
private function getMenuItems(string $menuId): array
126128
{
@@ -140,22 +142,30 @@ private function getMenuItems(string $menuId): array
140142

141143
if (isset($item[self::CATEGORY_ID_KEY])) {
142144
$catId = $item[self::CATEGORY_ID_KEY];
143-
$categoryIds[$catId] = $itemId;
145+
146+
if (isset($categoryIds[$catId])) {
147+
$categoryIds[$catId][] = $itemId;
148+
} else {
149+
$categoryIds[$catId] = [$itemId];
150+
}
144151
}
145152

146153
$itemsMap[$itemId] = $item;
147154
}
148155

149156
$collection = $this->collectionFactory->create();
150157
$categories = $collection
151-
->addFieldToSelect('url_path')
152-
->addIdFilter($categoryIds)
158+
->addAttributeToSelect('url_path')
159+
->addFieldToFilter('entity_id', ['in' => array_keys($categoryIds)])
153160
->getItems();
154161

155162
foreach ($categories as $category) {
156163
$catId = $category->getId();
157-
$itemId = $categoryIds[$catId];
158-
$itemsMap[$itemId]['url'] = DIRECTORY_SEPARATOR . $category->getUrlPath();
164+
$itemIds = $categoryIds[$catId];
165+
166+
foreach ($itemIds as $itemId) {
167+
$itemsMap[$itemId]['url'] = DIRECTORY_SEPARATOR . $category->getUrlPath();
168+
}
159169
}
160170

161171
return array_values($itemsMap);

0 commit comments

Comments
 (0)