Filter by Categories – only top-level visible?
Filter by Categories – only top-level visible? was created by keep2000
Posted 5 months 3 weeks ago #868
Hi there,When I use Phoca Cart / Custom Products as a dynamic content source, I noticed that in the “Filter by Categories” section, only the top-level categories are shown. Subcategories don’t appear at all.Is there a way to filter by those as well?
Or maybe have a checkbox like “Include child categories” to make that possible?Would be super helpful – thanks in advance! 😊
Or maybe have a checkbox like “Include child categories” to make that possible?Would be super helpful – thanks in advance! 😊
by keep2000
Please Log in or Create an account to join the conversation.
- JProStudio
-
Away
- Admin
-
- Posts: 433
- Thank you received: 69
Replied by JProStudio on topic Filter by Categories – only top-level visible?
Posted 5 months 3 weeks ago #870
We have tested the requested feature to filter categories by sub categories in our demo site seems it works well, find the attachment for your reference. Thank you
jmp.sh/s/qKX6ScPmJPScnRTNnmTs
jmp.sh/s/qKX6ScPmJPScnRTNnmTs
For urgent help please create a support ticket extensions.joomlapro.com/support/tickets
Last Edit:5 months 3 weeks ago
by JProStudio
Last edit: 5 months 3 weeks ago by JProStudio.
Please Log in or Create an account to join the conversation.
Replied by keep2000 on topic Filter by Categories – only top-level visible?
Posted 5 months 3 weeks ago #871
Oh, my apologies — I misread it. All the categories were indeed there, just listed flat in a single level, while I was expecting a more hierarchical display with indentation for subcategories.Would it be possible to show them indented by depth?Something like the following could work — it uses a single SQL query in the listener and a recursive PHP function to build the tree structure:
Alternatively, instead of short indentation, a breadcrumb-style format could also be used — although for deeply nested trees this might become harder to scan visually, especially if category names themselves already contain hyphens.
Code:
public static function getCategoryList($includeRoot = true)
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select(['id', 'title', 'parent_id'])
->from('#__phocacart_categories')
->where('published = 1')
->order('title ASC');
$db->setQuery($query);
$rows = $db->loadObjectList();
// Group categories by parent_id
$grouped = [];
foreach ($rows as $row) {
$grouped[(int)$row->parent_id][] = $row;
}
$output = [];
if ($includeRoot) {
$output[] = (object)['id' => 10000000, 'title' => 'Root'];
}
self::buildCategoryTree($grouped, 0, 0, $output);
return $output;
}
protected static function buildCategoryTree($grouped, $parentId, $depth, &$output)
{
if (isset($grouped[$parentId])) {
foreach ($grouped[$parentId] as $category) {
$prefix = str_repeat('– ', $depth);
$category->title = $prefix . $category->title;
$output[] = $category;
self::buildCategoryTree($grouped, $category->id, $depth + 1, $output);
}
}
}
Alternatively, instead of short indentation, a breadcrumb-style format could also be used — although for deeply nested trees this might become harder to scan visually, especially if category names themselves already contain hyphens.
Code:
protected static function buildCategoryTreeBreadcrumbLike($grouped, $parentId, $depth, &$output, $prefixPath = '')
{
if (isset($grouped[$parentId])) {
foreach ($grouped[$parentId] as $category) {
$fullPath = $prefixPath === '' ? $category->title : $prefixPath . ' – ' . $category->title;
$catCopy = clone $category;
$catCopy->title = $fullPath;
$output[] = $catCopy;
self::buildCategoryTreeBreadcrumbLike($grouped, $category->id, $depth + 1, $output, $fullPath);
}
}
}
by keep2000
Please Log in or Create an account to join the conversation.
- JProStudio
-
Away
- Admin
-
- Posts: 433
- Thank you received: 69
Replied by JProStudio on topic Filter by Categories – only top-level visible?
Posted 5 months 3 weeks ago #875
We have added the indentation for subcategories to improve the user access level and updated the package file, so kindly check after install the new file. Thank you
For urgent help please create a support ticket extensions.joomlapro.com/support/tickets
by JProStudio
Please Log in or Create an account to join the conversation.
Replied by keep2000 on topic Filter by Categories – only top-level visible?
Posted 5 months 3 weeks ago #876
cool, thank you
by keep2000
Please Log in or Create an account to join the conversation.
Time to create page: 0.458 seconds