@@ -90,6 +90,7 @@ public function __construct(
90
90
* @return array
91
91
*
92
92
* @throws NoSuchEntityException
93
+ * @throws \Magento\Framework\Exception\LocalizedException
93
94
*/
94
95
public function resolve (
95
96
Field $ field ,
@@ -121,6 +122,7 @@ public function resolve(
121
122
/**
122
123
* @param string $menuId
123
124
* @return array
125
+ * @throws \Magento\Framework\Exception\LocalizedException
124
126
*/
125
127
private function getMenuItems (string $ menuId ): array
126
128
{
@@ -140,22 +142,30 @@ private function getMenuItems(string $menuId): array
140
142
141
143
if (isset ($ item [self ::CATEGORY_ID_KEY ])) {
142
144
$ 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
+ }
144
151
}
145
152
146
153
$ itemsMap [$ itemId ] = $ item ;
147
154
}
148
155
149
156
$ collection = $ this ->collectionFactory ->create ();
150
157
$ categories = $ collection
151
- ->addFieldToSelect ('url_path ' )
152
- ->addIdFilter ( $ categoryIds )
158
+ ->addAttributeToSelect ('url_path ' )
159
+ ->addFieldToFilter ( ' entity_id ' , [ ' in ' => array_keys ( $ categoryIds)] )
153
160
->getItems ();
154
161
155
162
foreach ($ categories as $ category ) {
156
163
$ 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
+ }
159
169
}
160
170
161
171
return array_values ($ itemsMap );
0 commit comments