Skip to content

Commit

Permalink
Patch for wrong category names.
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredsgenkins committed May 12, 2020
1 parent 10324c9 commit d5e8a26
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Model/Resolver/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function __construct(
* @return array
*
* @throws NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function resolve(
Field $field,
Expand Down Expand Up @@ -121,6 +122,7 @@ public function resolve(
/**
* @param string $menuId
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getMenuItems(string $menuId): array
{
Expand All @@ -140,22 +142,30 @@ private function getMenuItems(string $menuId): array

if (isset($item[self::CATEGORY_ID_KEY])) {
$catId = $item[self::CATEGORY_ID_KEY];
$categoryIds[$catId] = $itemId;

if (isset($categoryIds[$catId])) {
$categoryIds[$catId][] = $itemId;
} else {
$categoryIds[$catId] = [$itemId];
}
}

$itemsMap[$itemId] = $item;
}

$collection = $this->collectionFactory->create();
$categories = $collection
->addFieldToSelect('url_path')
->addIdFilter($categoryIds)
->addAttributeToSelect('url_path')
->addFieldToFilter('entity_id', ['in' => array_keys($categoryIds)])
->getItems();

foreach ($categories as $category) {
$catId = $category->getId();
$itemId = $categoryIds[$catId];
$itemsMap[$itemId]['url'] = DIRECTORY_SEPARATOR . $category->getUrlPath();
$itemIds = $categoryIds[$catId];

foreach ($itemIds as $itemId) {
$itemsMap[$itemId]['url'] = DIRECTORY_SEPARATOR . $category->getUrlPath();
}
}

return array_values($itemsMap);
Expand Down

0 comments on commit d5e8a26

Please sign in to comment.