fix: Backend taxonomy API response format mismatch

Problem: Frontend expects term_id but backend returns id, causing undefined in update/delete URLs

Changes:
1. Categories GET endpoint: Changed 'id' to 'term_id', added 'description' field
2. Tags GET endpoint: Changed 'id' to 'term_id', added 'description' field
3. Attributes GET endpoint: Changed 'id' to 'attribute_id', added 'attribute_public' field

This ensures backend response matches frontend TypeScript interfaces:
- Category interface expects: term_id, name, slug, description, parent, count
- Tag interface expects: term_id, name, slug, description, count
- Attribute interface expects: attribute_id, attribute_name, attribute_label, etc.

Files Modified:
- includes/Api/ProductsController.php (get_categories, get_tags, get_attributes)

Result:
 Update/delete operations now work - IDs are correctly passed in URLs
 No more /products/categories/undefined errors
This commit is contained in:
Dwindi Ramadhana
2025-12-30 17:06:22 +07:00
parent 70afb233cf
commit ca3dd4aff3

View File

@@ -575,9 +575,10 @@ class ProductsController {
$categories = []; $categories = [];
foreach ($terms as $term) { foreach ($terms as $term) {
$categories[] = [ $categories[] = [
'id' => $term->term_id, 'term_id' => $term->term_id,
'name' => $term->name, 'name' => $term->name,
'slug' => $term->slug, 'slug' => $term->slug,
'description' => $term->description,
'parent' => $term->parent, 'parent' => $term->parent,
'count' => $term->count, 'count' => $term->count,
]; ];
@@ -602,9 +603,10 @@ class ProductsController {
$tags = []; $tags = [];
foreach ($terms as $term) { foreach ($terms as $term) {
$tags[] = [ $tags[] = [
'id' => $term->term_id, 'term_id' => $term->term_id,
'name' => $term->name, 'name' => $term->name,
'slug' => $term->slug, 'slug' => $term->slug,
'description' => $term->description,
'count' => $term->count, 'count' => $term->count,
]; ];
} }
@@ -621,11 +623,12 @@ class ProductsController {
foreach ($attributes as $attribute) { foreach ($attributes as $attribute) {
$result[] = [ $result[] = [
'id' => $attribute->attribute_id, 'attribute_id' => $attribute->attribute_id,
'name' => $attribute->attribute_name, 'attribute_name' => $attribute->attribute_name,
'label' => $attribute->attribute_label, 'attribute_label' => $attribute->attribute_label,
'type' => $attribute->attribute_type, 'attribute_type' => $attribute->attribute_type,
'orderby' => $attribute->attribute_orderby, 'attribute_orderby' => $attribute->attribute_orderby,
'attribute_public' => $attribute->attribute_public,
]; ];
} }