From ca3dd4aff309f5a399d3195fe2b749afaa06cda8 Mon Sep 17 00:00:00 2001 From: Dwindi Ramadhana Date: Tue, 30 Dec 2025 17:06:22 +0700 Subject: [PATCH] fix: Backend taxonomy API response format mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- includes/Api/ProductsController.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php index 869fbee..4c418a8 100644 --- a/includes/Api/ProductsController.php +++ b/includes/Api/ProductsController.php @@ -575,9 +575,10 @@ class ProductsController { $categories = []; foreach ($terms as $term) { $categories[] = [ - 'id' => $term->term_id, + 'term_id' => $term->term_id, 'name' => $term->name, 'slug' => $term->slug, + 'description' => $term->description, 'parent' => $term->parent, 'count' => $term->count, ]; @@ -602,9 +603,10 @@ class ProductsController { $tags = []; foreach ($terms as $term) { $tags[] = [ - 'id' => $term->term_id, + 'term_id' => $term->term_id, 'name' => $term->name, 'slug' => $term->slug, + 'description' => $term->description, 'count' => $term->count, ]; } @@ -621,11 +623,12 @@ class ProductsController { foreach ($attributes as $attribute) { $result[] = [ - 'id' => $attribute->attribute_id, - 'name' => $attribute->attribute_name, - 'label' => $attribute->attribute_label, - 'type' => $attribute->attribute_type, - 'orderby' => $attribute->attribute_orderby, + 'attribute_id' => $attribute->attribute_id, + 'attribute_name' => $attribute->attribute_name, + 'attribute_label' => $attribute->attribute_label, + 'attribute_type' => $attribute->attribute_type, + 'attribute_orderby' => $attribute->attribute_orderby, + 'attribute_public' => $attribute->attribute_public, ]; }