From 4d185f0c248818286aeecd1a315ee8fb2edddacb Mon Sep 17 00:00:00 2001 From: dwindown Date: Wed, 19 Nov 2025 23:13:52 +0700 Subject: [PATCH] fix: Product list display, redirect after create, and edit form data loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed 3 critical issues: 1. ✅ Price and Type Column Display Problem: Columns showing empty even though data exists Root Cause: price_html returns empty string for products without prices Solution: - Added fallback chain in index.tsx: 1. Try price_html (formatted HTML) 2. Fallback to regular_price (plain number) 3. Fallback to "—" (dash) - Added fallback for type: {product.type || '—'} Now displays: - Formatted price if available - Plain price if no HTML - Dash if no price at all 2. ✅ Redirect After Create Product Problem: Stays on form after creating product Expected: Return to products index Solution: - Changed New.tsx redirect from: navigate(`/products/${response.id}`) → navigate('/products') - Removed conditional logic - Always redirect to index after successful create User flow now: Create product → Success toast → Back to products list ✅ 3. ✅ Edit Form Not Loading Data Problem: Edit form shows empty fields instead of product data Root Cause: Missing fields in API response (virtual, downloadable, featured) Solution: - Added to format_product_full() in ProductsController.php: * $data['virtual'] = $product->is_virtual(); * $data['downloadable'] = $product->is_downloadable(); * $data['featured'] = $product->is_featured(); Now edit form receives complete data: - Basic info (name, type, status, descriptions) - Pricing (SKU, regular_price, sale_price) - Inventory (manage_stock, stock_quantity, stock_status) - Categories & tags - Virtual, downloadable, featured flags - Attributes & variations (for variable products) Result: ✅ Products list shows prices and types correctly ✅ Creating product redirects to index ✅ Editing product loads all data properly --- admin-spa/src/routes/Products/New.tsx | 8 ++------ admin-spa/src/routes/Products/index.tsx | 12 ++++++++++-- includes/Api/ProductsController.php | 3 +++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/admin-spa/src/routes/Products/New.tsx b/admin-spa/src/routes/Products/New.tsx index d694d93..d04aa2d 100644 --- a/admin-spa/src/routes/Products/New.tsx +++ b/admin-spa/src/routes/Products/New.tsx @@ -27,12 +27,8 @@ export default function ProductNew() { toast.success(__('Product created successfully')); queryClient.invalidateQueries({ queryKey: ['products'] }); - // Navigate to product detail or edit page - if (response?.id) { - navigate(`/products/${response.id}`); - } else { - navigate('/products'); - } + // Navigate back to products index + navigate('/products'); }, onError: (error: any) => { toast.error(error.message || __('Failed to create product')); diff --git a/admin-spa/src/routes/Products/index.tsx b/admin-spa/src/routes/Products/index.tsx index 4a0f165..ad53cc8 100644 --- a/admin-spa/src/routes/Products/index.tsx +++ b/admin-spa/src/routes/Products/index.tsx @@ -382,8 +382,16 @@ export default function Products() { - - {product.type} + + {product.price_html ? ( + + ) : product.regular_price ? ( + ${parseFloat(product.regular_price).toFixed(2)} + ) : ( + + )} + + {product.type || '—'} {__('Edit')} diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php index 00c382a..df14609 100644 --- a/includes/Api/ProductsController.php +++ b/includes/Api/ProductsController.php @@ -493,6 +493,9 @@ class ProductsController { $data['tags'] = $product->get_tag_ids(); $data['image_id'] = $product->get_image_id(); $data['gallery_image_ids'] = $product->get_gallery_image_ids(); + $data['virtual'] = $product->is_virtual(); + $data['downloadable'] = $product->is_downloadable(); + $data['featured'] = $product->is_featured(); // Gallery images $gallery = [];