Skip to content

Commit 2736551

Browse files
committed
feat: include object id in filter option data for hierarchical filter
1 parent d9f7204 commit 2736551

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/frontend.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ type FilterItem = {
5252
count: number;
5353
type: string;
5454
attributeQueryType?: 'and' | 'or' | undefined;
55-
parent?: string;
55+
id?: number;
56+
parent?: number;
5657
depth?: number;
5758
};
5859

plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterTaxonomy.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ function ( $term ) use ( $taxonomy_counts, $selected_terms, $taxonomy ) {
183183
);
184184

185185
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
186-
if ( isset( $term['depth'] ) ) {
186+
$option['id'] = $term['term_id'];
187+
188+
if ( isset( $term['depth'] ) && $term['depth'] > 0 ) {
187189
$option['depth'] = $term['depth'];
188190
}
189-
if ( isset( $term['parent'] ) ) {
191+
if ( isset( $term['parent'] ) && $term['parent'] > 0 ) {
190192
$option['parent'] = $term['parent'];
191193
}
192194
}

plugins/woocommerce/src/Internal/ProductFilters/TaxonomyHierarchyData.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private function build_full_hierarchy_map( string $taxonomy ): array {
186186
}
187187

188188
/**
189-
* Recursively build hierarchical term tree with depth and parent slug.
189+
* Recursively build hierarchical term tree with depth and parent.
190190
*
191191
* @param array $tree Reference to tree array being built.
192192
* @param int $term_id Current term ID.
@@ -198,9 +198,7 @@ private function build_full_hierarchy_map( string $taxonomy ): array {
198198
private function build_term_tree( &$tree, $term_id, $children, $temp_terms, $parent_id = 0, $depth = 0 ) {
199199
$tree[ $term_id ] = $temp_terms[ $term_id ];
200200
$tree[ $term_id ]['depth'] = $depth;
201-
if ( isset( $temp_terms[ $parent_id ] ) ) {
202-
$tree[ $term_id ]['parent'] = $temp_terms[ $parent_id ]['slug'];
203-
}
201+
204202
if ( ! empty( $children[ $term_id ] ) ) {
205203
foreach ( $children[ $term_id ] as $child_id ) {
206204
$this->build_term_tree( $tree[ $term_id ]['children'], $child_id, $children, $temp_terms, $term_id, $depth + 1 );

0 commit comments

Comments
 (0)