Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichaykin/d62b672c3cb0860cefc6ff3a1a13b341 to your computer and use it in GitHub Desktop.
Save ichaykin/d62b672c3cb0860cefc6ff3a1a13b341 to your computer and use it in GitHub Desktop.
diff --git a/app/functions/fn.categories.php b/app/functions/fn.categories.php
index c3fb61f159..06284fb602 100644
--- a/app/functions/fn.categories.php
+++ b/app/functions/fn.categories.php
@@ -624,7 +624,7 @@ function fn_get_categories_list_with_parents(array $category_ids, $lang_code = C
$parent_ids = explode('/', $category['id_path']);
array_pop($parent_ids);
- $category['parents'] = fn_sort_by_ids(
+ $category['parents'] = fn_get_items_by_ids(
$categories_list,
array_combine($parent_ids, $parent_ids),
'category_id'
diff --git a/app/functions/fn.common.php b/app/functions/fn.common.php
index e69ef4d00b..5bbf272022 100644
--- a/app/functions/fn.common.php
+++ b/app/functions/fn.common.php
@@ -8423,6 +8423,33 @@ function fn_sort_by_ids($items, $ids, $field = 'product_id')
return $tmp;
}
+/**
+ * Gets a list by the given ids
+ *
+ * @param array<array|object> $items List of items
+ * @param array<array|string> $ids Searched ids list
+ * @param string $field Search field
+ *
+ * @return array List of found items
+ *
+ * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
+ */
+function fn_get_items_by_ids($items, $ids, $field = 'product_id')
+{
+ $tmp = [];
+
+ foreach ($ids as $key => $id) {
+ foreach ($items as $item) {
+ if ($id === $item[$field]) {
+ $tmp[$key] = $item;
+ break;
+ }
+ }
+ }
+
+ return $tmp;
+}
+
/**
* Loads additional data related to given enities from corresponding tables.
* Each specified table triggers single SQL-query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment