public function getCategoryQueryTerm(Category $category, $store = null) { $queryType = $this->helper->getCategoryQueryType($store); if ($queryType == CategoryQueryType::NAME) { return $category->getName(); } $parents = $category->getParentCategories(); $parentIds = array_intersect($category->getParentIds(), array_keys($parents)); switch ($queryType) { case CategoryQueryType::FULL_PATH: break; case CategoryQueryType::NAME_AND_PARENT_NAME: $parentId = $category->getParentId(); $parentIds = in_array($parentId, $parentIds) ? [$parentId] : []; break; case CategoryQueryType::NAME_AND_ROOT_NAME: $parentIds = array_slice($parentIds, 0, 1); break; } $names = array_map(function ($id) use($parents) { return $parents[$id]->getName(); }, $parentIds); $names[] = $category->getName(); return implode(' ', $names); }